【发布时间】:2017-07-06 05:39:54
【问题描述】:
首先,这可行:<a ui-sref="students({courseId: $ctrl.Course.Id})">{{ student.Name }}</a>
这支持我的路由器工作正常。
我创建了一个自定义指令:link: "=link"
<div ng-if="$ctrl.link && $ctrl.link.Name && $ctrl.link.State">
<a ui-sref="{{$ctrl.link.State}}">{{$ctrl.link.Name}}</a>
</div>
为什么这行不通:
<div link="{ Name: 'View Students', State: 'students({courseId: $ctrl.Course.Id})' }">
这是错误:
转换拒绝($id:0 类型:6,消息:转换错误,详细信息:错误:参数值对状态“学生”无效)
更新: 我的自定义指令
angular.module('Foo').component('Bar', {
controller: LinkController,
templateUrl: "link.tpl.html",
transclude: true,
bindings: {
link: "=link",
});
【问题讨论】:
-
请发布您的指令的定义。
-
我添加了我的指令定义。
-
错误缩小了一点。您的
({courseId: $ctrl.Course.Id})没有被正确评估。看起来你在最后一个括号后面有一个浮动单引号。 -
这只是我的错字。我添加了另一个单引号。
-
这个
{courseId: $ctrl.Course.Id}是作为承诺的结果进行评估的吗?如果是 ,则您的指令无法知道承诺是履行还是拒绝。
标签: angularjs angularjs-directive ui-sref