Angular JS ng模型第一次没有正确启动

[英]Angular JS ng-model not initiating properly for the first time


I am using Angular JS ng-model to track the selected value of the select tag.

我正在使用Angular JS ng-model来跟踪select标签的选定值。

here's the example http://jsfiddle.net/8853oxb1/3/

这是http://jsfiddle.net/8853oxb1/3/的例子

function ControllerA($scope) {
    $scope.optionsArray = [1,2,3,4,5];
    $scope.optionsObject = {"India" : "IN" , "Singapore" : "SG", "Malaysia" : "MY", "Indonesia" : "INDY"};

}

If, I go to a dropdown by using a tab key and try to press "I" twice to select the second option starting with I, the dropdown value updates as expected, bu the ng-model just takes the value of the first option with "I". A bug in angular js or am I doing something wrong here?

如果,我使用Tab键进入下拉列表并尝试按“I”两次以选择以I开头的第二个选项,下拉值按预期更新,然后ng-model只取第一个选项的值“一世”。角js中的错误或我在这里做错了什么?

1 个解决方案

#1


2  

Have a look to the following jsfiddle

看看下面的jsfiddle

The main difference with your code is the way the dropdown is built.

与代码的主要区别在于下拉列表的构建方式。

Instead of feeding it with a single object

而不是用单个物体喂它

$scope.optionsObject = {"India" : "IN" , "Singapore" : "SG", "Malaysia" : "MY", "Indonesia" : "INDY"};

you have to change your data into something different, for instance, an array of object, like this:

你必须将数据更改为不同的数据,例如,一个对象数组,如下所示:

$scope.optionsObject = [ { name: "India", code: "IN" }, { name: "Singapore", code: "SG" }, { name: "Malaysia", code: "MY" }, { name: "Indonesia", code: "INDY" } ];
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2015/05/20/83028a71b8530871072b8db30a51e136.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告