AngularJs Array Push


AngularJs Array Push Values- It is very simple to push a value in AngularJs Array . push() method is used to push an element in AngularJs array. Here in this tutorial we are going to explain how you can use push() method to insert an element in AngularJs Array. You can use our online demo try and edit the code online.


AngularJs Array Push Values | Example

You can use push() method to push an element in an array. Here is full example –

AngularJs Array Push Values | Example:

<!DOCTYPE html>
<html lang="en">
<head>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
 <script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
 $scope.exampleArray = ['Mango','Banana'];
 $scope.pushInArray = function() {
	 // get the input value
	 var inputVal = $scope.arrInput;
	 $scope.exampleArray.push(inputVal);
	 
 };
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController"> 
 
 Enter a value and click "Push" Button to insert in array.
 <input type="text" name="arrExample" ng-model="arrInput"><br>
 <button ng-click='pushInArray()' >Push</button><br>
 Array = {{exampleArray}}<br>

</div> 
</div>
</body>  
</html>  

Try it »

In the above example we have created a simple example to push elements in array in AngularJs.

If you run the above example it will produce the output something like this –

AngularJs Array Push


Advertisements

Add Comment

📖 Read More