AngularJS extends HTML with ng-directives:
AngularJS usually have a data model which is a collection of data available for the application.
Additional directives will be discussed later:
In the code below:
<!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <body>
<div ng-app=""> <p>Enter Your Name: <input type="text" ng-model="name"></p> <p ng-bind="name"></p> </div>
</body> </html>
You could set initial default value(s) of an application data or variables using the ng-init directive like this:
<div ng-app="" ng-init="name='John Doe'">
NOTE: Instead of using the ng-init directive, you will learn how to set initial values later using a module and controller.
If you are NOT requiring a user to input data but just want to bind the application variable DIRECTLY to an HTML element, the ng-model directive is not used:
<div ng-app="" ng-init="name='Cornelius'">
<p>My name is <span ng-bind="name"></span></p>
</div>
NOTE: This will result in the phrase "My name is Cornelius" when the page loads. Use data-ng- instead of ng- to make page HTML valid.