Angularjs ui sref未生成href
我不确定我在这里犯了什么错误,但是href没有生成。我已经按照ui路由器示例进行了配置,但当我将ui sref放入ng时,重复它不会生成URL,并且当我手动键入URL时,它也不工作 即使我绑定到设置值,如Angularjs ui sref未生成href,angularjs,angular-ui-router,Angularjs,Angular Ui Router,我不确定我在这里犯了什么错误,但是href没有生成。我已经按照ui路由器示例进行了配置,但当我将ui sref放入ng时,重复它不会生成URL,并且当我手动键入URL时,它也不工作 即使我绑定到设置值,如data ng click=“widget.open({widgetId:1})也不会发生任何事情 这是我的代码片段 配置: .config(['$stateProvider', '$urlRouterProvider', '$locationProvider', functio
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>
我的小部件({Widgets.length}})
偶像
有人能指出我的错误吗
谢谢无需将小部件.id
用大括号括起来:
data-ui-sref="widget.open({widgetId: {{widget.id}} })
使用:
我认为您的问题是命名问题。您所在的中继器是widgets
中的小部件,因此当您执行小部件.open
时,我认为它是在中继器的小部件对象中寻找一个打开的函数,而不是子路径“widget.open”。我也尝试过这个方法,但没有成功,请参见模板中的注释代码。我已经找到了我也更改了变量名,但不起作用。我不能告诉你在注释掉的代码中重命名了什么。你在data ng repeat
中放了什么?我已经更新了我的代码。data ng repeat
将有对象数组[{id:1233,name:'xyz',…}]
.Hmm好的,那么我要明确的是,中继器是否工作了?它是否真的在你的对象数组中迭代并显示所有内容?还是什么都不工作?我假设是这样,但我只想在前进之前覆盖所有基础。是的,ng repeat工作正常。我已经使用ng ro重写了相同的代码ute和它现在正在工作。我现在已经删除了ui路由器。
data-ui-sref="widget.open({widgetId: widget.id })">