How to initiate variables in AngularJS?

The ng-init directive initialize AngularJS application variables.

Sample Code:

<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div data-ng-app="" data-ng-init="firstName='John'">
<p>The firstname is <span data-ng-bind="firstName"></span></p>
</div>
</body>
</html>

Output:


Cheers!!!

No comments:

Post a Comment