[英]ngRepeat in custom directive - interpolation
正在创建自定义指令以填充下拉菜单,但是尝试在我的指令中设置<li>
的ng-repeat
属性时遇到了问题。
我期望这会使用ng-repeat
为我的工具的每个环境创建一个下拉选项。
我在控制台中没有收到任何错误,但是未按预期插值$scope
变量。
这是我的指令:
myApp.directive("toolsMenu", function () {
return {
replace: true,
transclude: true,
templateUrl: 'js/directives/toolsMenu.html',
scope: {
inputObject: '=',
environment: '=',
tool: '@'
}
}
});
这是 toolsMenu.html
文件:
<li class="tool">{{inputObject.name}}
<ul class="environment">
<li ng-repeat="environment in {{tool}}"><a ng-href="{{ environment.url }}" alt="{{inputObject.name}} {{ environment.environment }}" target="_blank">{{ environment.environment }}</a></li>
</ul>
</li>
这就是我从主HTML文件中调用指令的方式:
<tools-menu input-object="continuusInput" environment="continuus" tool="continuus"></tools-menu>
在此示例中,“工具”实际上应该是“ continuus”,但仅显示为“ tool”。
尝试
<li ng-repeat="environment in tool"><a ng-href="environment.url" alt="{{inputObject.name + environment.environment}}" target="_blank">{{ environment.environment }}</a></li>
在html上定义属性时,无需添加方括号({{}})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.