如何让ui

系统教程 行业动态 更新时间:2024-06-14 16:52:52
如何让ui-sref在trustAsHtml中工作?(How to get ui-sref working inside trustAsHtml?)

我有一个活动状态,当没有任何活动时,我想显示一条消息。 所以我创建了一个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.

更多推荐

本文发布于:2023-04-05 12:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/f0c06894cb1d7823e92bb6c71e12ec5b.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ui

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!