角度:动态分配ng选项,奇怪的行为

angular: assigning ng-options dynamically, strange behavior

本文关键字:动态分配 ng 选项 角度      更新时间:2023-09-26

我正在构建一个内联可编辑的表单。

我的指令将 ng 选项传递给模板。翡翠锉:

div(input-inline-select="myobj.val" options="c.name for c in codes" tabindex="1")

在指令中:

scope.options = attr.options;

在呈现的模板中,选择:

div(class="input_inline_edit_div")
  {{options}} 
  select(class="inline_edit_select" ng-options="{{options}}" ng-model="model" on-enter="save()" on-esc="cancel()" ng-show="editMode" tabindex="{{tabindex}}" ng-focus="edit()")
  span(ng-mouseenter="showEdit = true" ng-mouseleave="showEdit = false")
    span(ng-hide="editMode" ng-click="edit()" )
      div(class="inline_edit_text")
        {{model}}

发生的情况是,第一个{{options}}正确打印c.name for c in codes,但ng-options="{{options}}"的那个没有,并且代码实际上中断并且没有可见的选项。知道这是为什么吗?为什么选项可以正确扩展其"自身"而不是作为属性值展开?

删除{{}}

ng-options="options"