How to create your first AngularJS Application
This article mainly introduces how to create your first AngularJS application. AngularJS is a very popular JavaScript framework. For more information, see
Follow these steps to create an AngularJS Application
Step 2: load the framework
As a pure JavaScript framework, it can be added using the <script> tag.
?
| 1 2 |
<Script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"> </Script> |
Step 2: Use the ng-app command to define AngularJS applications
?
| 1 2 3 |
<Div ng-app = ""> ... </Div> |
Step 1: Use the mode name defined by the ng-model command
?
| 1 |
<P> Enter your Name: <input type = "text" ng-model = "name"> </p> |
Step 2: Use the ng-bind command to bind the values in the above model to the definition.
?
| 1 |
<P> Hello <span ng-bind = "name"> </span>! </P> |
Follow these steps to run AngularJS applications
Use the three steps mentioned above to go To the HTML page.
TestAngularJS.html
?
| 1 2 3 4 5 6 7 8 9 10 11 |
<Html> <Title> AngularJS First Application </title> <Body> <H1> Sample Application <Div ng-app = ""> <P> my name: <input type = "text" ng-model = "name"> </p> <P> Hello, <span ng-bind = "name"> </span>! </P> </Div> <Script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"> </script> </Body> </Html> |
Output
Open textangularjs.html in the webbrowser. Enter the name and the result.
How to integrate AngularJS with HTML
- The ng-app command indicates the beginning of the AngularJS application.
- The ng-model command creates a model variable named "name" on the HTML page, and the ng-app command is used in the div.
- Ng-bind the model name is displayed in the HTML span tag as long as what you enter in the text box.
- The end </div> flag indicates the end of The AngularJS application.