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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -