2016-07-15 77 views
1

我有一个字符串数组,即帐号。当点击表格中的记录时,我提供一个更新记录的模式,其中一个字段是账号。这显示了一些正确但似乎损失了与vm.accountNumber绑定的双向绑定,但也显示了模型的值。角度选择模型未设置值

vm.accountNumber总是有一个值,当点击表格行进行编辑时,该值被设置。尽管有这个模型,但它从来没有让它成为选择。我怀疑我失去了双向链接,并且正在为模型创建自己的变量。

<select class="ui search fluid selection dropdown" id="accountSearch" ng-model="vm.accountNumber"> 
      <!--ng-options="account for account in vm.accounts.slice(1)">--> 
      <option ng-repeat="account in vm.accounts | limitTo: vm.accounts.length : 1" value="account" ng-selected="account == vm.accountNumber">{{account}}</option> 
    </select> 

下面是accounts数组的一个片段。 0 “ - ” 1: “0001” 2: “0002” 3: “0003” 4: “0004”

回答

3

我想说的只是使用ng-options指令,而不是ng-repeat荷兰国际集团option

<select class="ui search fluid selection dropdown" 
    id="accountSearch" ng-model="vm.accountNumber" 
    ng-options="account for account in vm.accounts"> 
</select> 

Demo Plunkr


虽然我想指出你的问题是与期权价值属性,

你应该改变

value="account" 

value="{{account}}" 
+0

虽然我同意我喜欢NG选项,你可以看到注释掉我尝试的选项,以及再甚至试图做一个NG - 选择的表达。都没有工作。价值没有改变,但谢谢:) – user1552172

+0

我可以知道什么是'vm.accounts.slice(1)'?你能否也请添加'vm.accounts' json? –

+0

这只是跳过了“ - ”的第一个结果。更新数组的问题。 – user1552172