Is it possible to create an array using ng-init
dynamically?
The bellow code is not working
ng-init="medi_count = new Array(5)"
Is it possible to create an array using ng-init
dynamically?
The bellow code is not working
ng-init="medi_count = new Array(5)"
Angular expression is not same like JavaScript expression. It has some limits.!
No Object Creation With New Operator: You cannot use new operator in an Angular expression.
Refer Angular Documentation : Angular Expression
Sure you can its just the same way you create Arrays..
<!DOCTYPE html>
<html ng-app>
<head>
<script src="https://code.angularjs.org/1.4.9/angular.js"></script>
</head>
<body>
<div ng-init="names=[{name:'Shijin',city:'NewYork'}, {name:'John',city:'Montana'},{name:'Phillip',city:'California'}]">
<ul>
<font face="Impact" color="purple" size = "5"><li data-ng-repeat="Objects in names">{{Objects.name}} - {{Objects.city}}</li></font>
</ul>
</div>
</body>
</html>
ng-init is for loading data into an array, as other answer shows. If you just want a new empty array, then make it in the controller
$scope.medi_count = [];
You can do it pretty fine by calling a function
<div ng-init="medicount(5)">
where
$scope.medicount = function(someNumber){
//what you want
}
as answered in this question