[英]ui-sref not generating the href
我不确定我在这里犯了什么错误,但是href并未生成。 我已经按照ui-router示例进行了配置,但是当我将ui-sref放在ng-repeat中时,它不会生成URL,并且当我手动键入URL时,它也无法正常工作。
即使我绑定设置data-ng-click="widget.open({widgetId: 1})
也不会发生任何事情。
这是我的代码段。
配置:
.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
function ($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise('/');
$locationProvider.html5Mode(true);
$stateProvider
.state('home', {
url: '/',
templateUrl: '/templates/home/home.html'
})
.state('widget', {
// With abstract set to true, that means this state can not be explicitly activated.
// It can only be implicitly activated by activating one of its children.
abstract: true,
// This abstract state will prepend '/widgets' onto the urls of all its children.
url: '/widget',
// Loading a template from a file. This is also a top level state,
// so this template file will be loaded and then inserted into the ui-view
// within index.html.
templateUrl: '/templates/widgets/index.html'
})
.state('widget.open', {
url: '/{widgetId:[\w+$]}', //matches [a-zA-Z_0-9]
templateUrl: '/templates/widgets/index.html'
})
.state('widget.create', {
url: '/{type:[a-zA-Z]}', // We can test enum list also
templateUrl: '/templates/widgets/index.html'
})
.state('mashup', {
// With abstract set to true, that means this state can not be explicitly activated.
// It can only be implicitly activated by activating one of its children.
abstract: true,
// This abstract state will prepend '/mashups' onto the urls of all its children.
url: '/mashup',
// Loading a template from a file. This is also a top level state,
// so this template file will be loaded and then inserted into the ui-view
// within index.html.
templateUrl: '/templates/mashups/index.html'
})
.state('mashup.open', {
url: '/{mashupId:[\w+$]}', //matches [a-zA-Z_0-9]
templateUrl: '/templates/mashups/index.html'
})
.state('mashup.create', {
url: '/{templateType:[a-zA-Z]}', // We can test enum list also
templateUrl: '/templates/mashups/index.html'
});
}])
模板:
<div class="panel panel-default widget-list">
<div class="panel-heading">
<h3 class="panel-title">My Widgets ({{widgets.length}})</h3>
</div>
<div class="panel-body hp-content">
<table class="table table-condensed table-bordered">
<tbody>
<tr data-ng-repeat="w in widgets">
<td class="hp-type">Icon</td>
<td>
<div class="row">
<div class="col-xs-12">
<a data-ui-sref="widget.open({widgetId: w.id })">{{::w.name}}</a>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-6">
{{::w.sourceId}}
</div>
<div class="col-xs-12 col-md-6">
{{::w.communityId}}
</div>
</div>
</td>
<td class="hp-actions">{{::w.access}}</td>
</tr>
</tbody>
</table>
</div>
<div class="panel-footer">Panel footer</div>
</div>
谢谢
不需要将widget.id
在花括号中:
data-ui-sref="widget.open({widgetId: {{widget.id}} })
采用:
data-ui-sref="widget.open({widgetId: widget.id })">
我认为您的问题是一个命名问题。 您位于widget in widgets
的中继器widget in widgets
,因此当您执行widget.open
,我认为它是在中继器的小部件对象中而不是子路由“ widget.open”中寻找开放功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.