Ng-Init-3

 

In this example, ng-init will initialize array of objects named Arrs and the field of array arr.name is bind with ng-options in drop-down list which generate list of options in drop-down as name of flowers. ng-init code: ng-init="Arrs=[{name:'Tulip'},{name:'Sunflower'},{name:'Merrygold'}];name='Tulip'" See code snippet:

 
 
 
<!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'}];name='Tulip'"> Flowers <select ng-model="name" ng-options="arr.name as arr.name for arr in Arrs"></select> </div> </div> </body> </html>
Output