What is the angularjs way to databind many inputs?

后端 未结 5 1057
攒了一身酷
攒了一身酷 2020-11-28 22:07

I\'m learning angularjs and I want to be able let the user enter many inputs. When these inputs are entered the list array elements should change accordingly. I

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 22:28

    You'll have better luck if your list is an array of objects (as opposed to an array of primitives). This works fine even though a new scope is created with ng-repeat:

    with a controller of:

    function TestController($scope) {
        $scope.list = [ { value: 'value 1' }, { value: 'value 2' }, { value: 'value 3' } ];
    }​
    

    See this fiddle as an example.

    On the other hand if you are trying to bind to an array of strings the new scope will cause a problem as the values you are modifying will not be tied to the original array string primitives (as in this fiddle example).

提交回复
热议问题