Angularjs adding html to variable with ui-sref link(Angularjs使用ui-sref链接将html添加到变量)
问题描述
我有以下代码将 html 添加到变量中.但是,当它显示在页面上时,链接不起作用.
I have the following code that adds html to a variable. However, when it get's shown on the page, the link doesn't work.
动态插入 ui-sref
链接的最佳方法是什么?
What's the best way to get a ui-sref
link to work when inserting it dynamically?
JAVASCRIPT
.controller('page', function($scope, $rootScope, $http, $state, $sce) {
$scope.message = $sce.trustAsHtml('A <a ui-sref="login">login</a> link');
})
HTML
<div ng-bind-html="message"></div>
推荐答案
有 一个工作插件
我想说,我们可以使用以下组合:
I would say, that we can use combination of:
$state.href()
(doc 这里)和ng-href
(doc 这里)
(但仅在传递的参数是 url 的一部分的情况下)
这就是结果
<a ng-href="{{$state.href(myStateName, myParams)}}">
现在(在 plunker)将 myStateName 更改为 parent
, parent.child
, home
它将正确更改生成的href:
And now (in the plunker) we can change myStateName into parent
, parent.child
, home
and it will change properly the generated href:
<input ng-model="myStateName" />
<input ng-model="myParams.param" />
因为这些是 plunker 中的状态
Because these are states in plunker
$stateProvider
.state('home', {
url: "/home",
...
})
.state('parent', {
url: "/parent?param",
...
})
.state('parent.child', {
url: "/child",
...
检查它这里
这篇关于Angularjs使用ui-sref链接将html添加到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Angularjs使用ui-sref链接将html添加到变量


- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01