我有一个活动状态,当没有任何活动时,我想显示一条消息。 所以我创建了一个if / else语句,用于检查$ scope活动是否有任何内容,如果不是,则将特定的代码注入模板。
if(!$scope.activities.length){ var empty = function(){ $scope.renderHtml = function (htmlCode) { return $sce.trustAsHtml(htmlCode); }; $scope.body = '<div>There are no activities yet, <a ui-sref="home.users">click here to start following some friends!</a></div>'; } empty() }问题是ui-sref不起作用,然而一个正常的'a href`确实起作用。 对于这个问题,还有什么可靠的解决方案吗?
I have a activity state, and when there are no activities I would like to display a message. So I created a if/else statement that checks if the $scope activities has any content, if not it injects a certain code into the template.
if(!$scope.activities.length){ var empty = function(){ $scope.renderHtml = function (htmlCode) { return $sce.trustAsHtml(htmlCode); }; $scope.body = '<div>There are no activities yet, <a ui-sref="home.users">click here to start following some friends!</a></div>'; } empty() }The problem is that ui-sref doesn't work, a normal 'a href` does work though. Are there any solid work arounds for this problem?
最满意答案
为了完成这项工作,我使用ng-show创建了一个元素,
%div{"ng-show" => "activitiesHide"}而这个JS,
activitiesService.loadActivities().then(function(response) { $scope.activities = response.data; if(!$scope.activities.length){ $scope.activitiesHide = response.data } })我将服务的结果放在活动范围内,然后检查js是否有内容。 如果没有激活activitesHide秀。
To get this work I created a element with ng-show,
%div{"ng-show" => "activitiesHide"}And this js,
activitiesService.loadActivities().then(function(response) { $scope.activities = response.data; if(!$scope.activities.length){ $scope.activitiesHide = response.data } })I place the results from the service in the activities scope, and then check in the js if it has content. If not activate the activitesHide show.
更多推荐
发布评论