Ng-Init-2

 

In this example, ng-init will initialize array of objects and we will be using the array in ng-repeat. ng-init code: ng-init="Arrs=[{name:'Tulip'},{name:'Sunflower'},{name:'Merrygold'}]" "arr.name" access the name of objects and display as it.

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app> <div> <div ng-init="Arrs=[{name:'Tulip'},{name:'Sunflower'},{name:'Merrygold'}]"> <div ng-repeat="arr in Arrs">{{arr.name}}</div> </div> </div> </body> </html>
Output