angularjs push to array adding ten elements

I'm new to AngularJS, and this has been driving me nuts for several days. HELP!!! I've condensed the problem into as simple a code snippet as I could.. I've set up an array called indexArray in the Controller, and I want to push values to it from HTML via the function pushIndex(). The problem is that the push function adds ten identical elements to the array. When I list the array with the {{indexArray}} statement after the push, it looks like this:


Where I only wanted one "9" pushed, it added ten of them.

The same thing happens with strings, quotes, etc.

<script src=""></script> <script src=""></script> <script>  var app = angular.module('myDataApp',[]); app.controller('myDataController',function($scope, $http){     $scope.indexArray=[4,5,6,7];     $scope.pushIndex=function(num){         $scope.indexArray.push(num);    }; }); </script> </head> <body> <div ng-app="myDataApp" ng-controller="myDataController"> {{ pushIndex(9) }} {{ indexArray }} </div> </body> </html> 

Sorry in advance if the solution is painfully simple or this question has been asked before. Thanks! -UDM


Category: arrays Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.105 (s). 12 q(s)