javascript - Binding to Elements of Arrays in AngularJS -
in angularjs, can bind text inputs elements of arrays:
<input type="text" ng-model="foo[2]" />
is allowed, or work accident?
when try bind select
elements or checkbox input array elements fail work - i.e. select
element not change displayed, or bound, value on selection , checkbox not display tick when clicked.
am missing here?
update: works in jsfiddle: http://jsfiddle.net/azfzc/
it work on select elements
look jsfiddle http://jsfiddle.net/fste7/
html
<div ng-app> <div ng-controller="mycontroller"> select <select ng-change="changed()" ng-options="option.value option.label option in options" ng-model="ar[0]"> </select> </div> </div>
js
function mycontroller($scope){ $scope.options = [ { label : "first element", value : 0 }, { label : "second element", value : 1 }, ] $scope.ar = []; $scope.ar[0] = 0; $scope.changed = function(){ console.log($scope.ar[0]); } }
Comments
Post a Comment