angularjs - Why does my view not update for an array within an array? -


i have simple form accepts input , adds array. worked fine when 1 array , view updated.

however when created 2 arrays, each own array , updated inner array view not update.

why happen , how can fix it?

here view:

<div ng-app="test" ng-controller="testcontroller">      <div ng-repeat="group in groups">          <form ng-submit="submit($index)" ng-controller="testcontroller">             enter text , hit enter:             <input type="text" ng-model="text" name="text"/>             <input type="submit" id="submit" value="submit"/>             <pre>list={% verbatim %}{{ list }}{% endverbatim %}</pre>             <pre>group.people={% verbatim %}{{ group.people }}{% endverbatim %}</pre>         </form>      </div> </div> 

and here's controller:

(function () {  // small groups application module var testapp = angular.module('test', []);  testapp.controller('testcontroller', [     '$http',     '$scope',     function ($http, $scope) {          $scope.groups = [];         $scope.list = [];         $scope.text = 'hello';          (var ii = 0; ii < 2; ii++) {             var group = {};             group.people = [];             $scope.groups.push(group);         }          $scope.submit = function (groupid) {             $scope.list.push($scope.text);             $scope.groups[groupid].people.push($scope.text);             console.debug($scope.groups[groupid].people);             $scope.text = '';         };     }]);  })(); 

your appreciated.

solved. help. here's solution.

for view use 1 instance of controller , use form.text ngmodel.

<div ng-app="test" ng-controller="testcontroller">      <div ng-repeat="group in groups">          <div ng-repeat="person in group.people">             {% verbatim %}{{ person }}{% endverbatim %}         </div>          <form ng-submit="submit($index)">             enter text , hit enter:             <input type="text" ng-model="form.text" name="text">             <input type="submit" id="submit" value="submit">         </form>          <pre>list={% verbatim %}{{ list }}{% endverbatim %}</pre>         <pre>group.people={% verbatim %}{{ group.people }}{% endverbatim %}</pre>     </div> </div> 

for controller update use $scope.form.text.

        $scope.groups = [];         $scope.list = [];         $scope.form = {};         $scope.form.text = 'hello';          (var ii = 0; ii < 2; ii++) {             var group = {};             group.people = [];             $scope.groups.push(group);         }          $scope.submit = function (groupid) {             $scope.list.push($scope.form.text);             $scope.groups[groupid].people.push($scope.form.text);             console.debug($scope.groups[groupid].people);             $scope.form.text = '';         }; 

thanks!


Comments