简体   繁体   English

ngRepeat自定义指令-插值

[英]ngRepeat in custom directive - interpolation

Working on creating a custom directive to populate a drop-down menu, but am facing problems when trying to set the ng-repeat attribute of the <li> in my directive. 正在创建自定义指令以填充下拉菜单,但是尝试在我的指令中设置<li>ng-repeat属性时遇到了问题。

I am expecting this to create a drop down option for each environment of my tool, using ng-repeat . 我期望这会使用ng-repeat为我的工具的每个环境创建一个下拉选项。

I am not getting any errors in the console, but the $scope variable is not being interpolated as expected. 我在控制台中没有收到任何错误,但是未按预期插值$scope变量。

Here is my directive: 这是我的指令:

myApp.directive("toolsMenu", function () {
   return {
       replace: true,
       transclude: true,
       templateUrl: 'js/directives/toolsMenu.html',
       scope: {
           inputObject: '=',
           environment: '=',
           tool: '@'
       }
   } 
});

Here is the toolsMenu.html file: 这是 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>

This is how I call my directive form the main HTML file: 这就是我从主HTML文件中调用指令的方式:

<tools-menu input-object="continuusInput" environment="continuus" tool="continuus"></tools-menu>

This is the console output open running the page: 这是控制台输出打开的运行页面: 在此处输入图片说明

In this example, the "tool" is actually supposed to be 'continuus', but it is only appearing as 'tool'. 在此示例中,“工具”实际上应该是“ continuus”,但仅显示为“ tool”。

Try 尝试

<li ng-repeat="environment in tool"><a ng-href="environment.url" alt="{{inputObject.name + environment.environment}}" target="_blank">{{ environment.environment }}</a></li>

You don't need to add brackets ({{}}) when defining attributes on html 在html上定义属性时,无需添加方括号({{}})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM