Ng-Init-8

 
In this example, We will initialize some fields of form with ng-init directive and initialized values are bind with ng-model of different controls, Here is the code for ng-init: ng-init="Cricket=true;Football=true;lastName='Last Name';firstName='First Name';gender='Male'" See the example
 
 
 
<!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> <form ng-init="Cricket=true;Football=true;lastName='Last Name';firstName='First Name';gender='Male'"> First Name <input type="text" ng-model="firstName" /><br /><br /> Last Name <input type="text" ng-model="lastName" /><br /><br /> Gender:<input type="radio" ng-model="gender" name="gender" value="Male" />Male <input type="radio" ng-model="gender" name="gender" value="Female" />Female<br /><br /> Hobbies<br /> <input type="checkbox" ng-model="Cricket" />Cricket <input type="checkbox" ng-model="Football" />Football <input type="checkbox" ng-model="Tennis" />Tennis <input type="checkbox" ng-model="Badminton" />Badminton<br /><br /> <input type="button" value="Save" /> <input type="button" value="Cancel" /> </form> </div> </body> </html>
Output