bry*_*yan 6 javascript angularjs angular-ui-router
我有以下代码将html添加到变量.但是,当它显示在页面上时,链接不起作用.
ui-sref在动态插入链接时获取链接的最佳方法是什么?
JAVASCRIPT
.controller('page', function($scope, $rootScope, $http, $state, $sce) {
$scope.message = $sce.trustAsHtml('A <a ui-sref="login">login</a> link');
})
Run Code Online (Sandbox Code Playgroud)
HTML
<div ng-bind-html="message"></div>
Run Code Online (Sandbox Code Playgroud)
我想说,我们可以使用以下组合:
(但仅限于传递的参数是 url 的一部分的情况)
这将是结果
<a ng-href="{{$state.href(myStateName, myParams)}}">
Run Code Online (Sandbox Code Playgroud)
现在(在plunker中)我们可以将myStateName更改为parent, parent.child,home它将正确更改生成的 href:
<input ng-model="myStateName" />
<input ng-model="myParams.param" />
Run Code Online (Sandbox Code Playgroud)
因为这些都是 plunker 中的状态
$stateProvider
.state('home', {
url: "/home",
...
})
.state('parent', {
url: "/parent?param",
...
})
.state('parent.child', {
url: "/child",
...
Run Code Online (Sandbox Code Playgroud)
在这里检查一下
| 归档时间: |
|
| 查看次数: |
3194 次 |
| 最近记录: |