javascript - $scope.push failing to update after entering same value in Angular (bug!) -
i new angular , trying hands on few functions. found strange behavior when try re-enter same value.
<!-- html --> <body ng-app="angular-test"> <div ng-controller="formcontroller"> <ul> <li ng-repeat="name in names">{{name}}</li> </ul> <form ng-submit="addname()"> <input type="text" ng-model="newname"> <input type="submit" value="add"> </form> </div> </body> /*** angular code ***/ (function() { var app = angular.module("angular-test", []); app.controller("formcontroller",formcontroller); function formcontroller($scope){ $scope.names = ['israel','agyeman','prempeh','osei','apea']; $scope.addname = function(){ $scope.names.push($scope.newname); $scope.newname = ''; } } })(angular);
![a list generated existing model in html page][1]
- israel
- agyeman
- prempeh
- osei
- apea
- king
king
______________ [add] (input form)
"king" added through add button "king" typed "king" again failed update , not update afterwards no matter insert. ideas causing this?
evening israel,
you can't duplicate values in repeater. make works, add following:
name in names track $index
or see in action: http://codepen.io/anon/pen/xgzrkk
hope helps!
Comments
Post a Comment