I am trying to input some color name and if the color is not present in the list it should get added to it and the li element should also get that particular color. I dont understand whats wrong with this
<!DOCTYPE html> <html> <head></head> <body ng-app="colors"> <div ng-controller="mainCtrl as ctrl"> <ul ng-repeat="color in ctrl.colors"> <li ng-bind="color.label" ng-style="{color:color.label}"> </ul> <input type="text" ng-model="ctrl.colordisp"></input> {{ctrl.colordisp}} </div> <button type="button" ng-click="ctrl.checkColor()">submit</button> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <script> angular.module("colors",[]) .controller("mainCtrl",[function(){ var self=this; self.colors=[ {label:"red"}, {label:"blue"}, {label:"green"} ]; self.colordisp="red"; self.checkColor=function(){ angular.forEach(self.colors,function(c){ if(c.label!==self.colordisp){ self.colors.push("label:"+self.colordisp); } }); }; }]); </script> </body> </html>