----------------------- Page 5----- ------ ------ ------
AngularJS? What is it?
AngularJS (official site) is a JavaScript framework open-source (search for the definition of open-source and
framework) developed by Google. It has been created by Miško Hevery (in 2010). 1.0 (First version called
stable) date of June 2012.
This framework greatly facilitates the development of web application according to the MVC (Model View Controller).
We will have the opportunity to return later on these concepts, but you may have already had the opportunity to use the
web applications (often called "web app" ). For example Gmail and GoogleDoc are "web app" (internet site
resembling applications "conventional" ).
HTML 코드 ex1.html
테스트 angularjs< /title> <br /> <script src= "lib/ 각도.js">min </script> <br /> <script src= "javascript/ex1.js" > </script> <br /> </head> <body <br /> NG-app> <br /> <h1 NG- 컨트롤러= " moncontrol" > {{myvariable}} < /h1> <br /> < /body> </html <br /> <br /><br />> JavaScript 코드 ex1.js moncontrol <br /><br /> 기능( ) 달러 범위) { <br />$ 범위.myvariable= " Hello World! "; <br /></span>Note Although AngularJS is not a "software", you will therefore produce code (HTML, JavaScript, and CSS).
First approach
AngularJS will allow us to add new attributes to HTML tags, all these new attributes
will begin by: ng-
For example we can have ....... < /p>
er
This will make our dynamic HTML page (the
data displayed will evolve in the course of time). These "variables" will be easily recognizable, because they
will be framed by curly braces: { {MYVARIABLE}}
example: { {montitre} } < /h1 >.
The browser does not display { {montitre} }, but the value contained in the "variable" montitre.
A prime example
to make you even
In our 1 example we will use 2 attributes made by AngularJS: ng-app and ng-controller, but there are
a lot of other that we will consider later in this document.
We are going to be able to introduce what we call for the moment of "variables" directly in the HTML code
(these "variables" can be controlled with the JavaScript).HTML code ex1.html
< !DOCTYPE html>
Test AngularJS< /title> <br /> <script src= "lib/angular.min. js" > < /script> <br /> <script src= "javascript/ex1.js" > < /script> <br /> < /head> <br /> <body ng-app> <br /> <h1 ng-controller= "moncontrol" > { {MYVARIABLE} } < /h1> <br /> < /body> <br /> < /html> <br /><br />JavaScript code ex1.js <br /><br />function moncontrol( $scope){ <br /> $scope.MYVARIABLE= "Hello World! "; <br /></span>}
A few remarks on the content of the head tag of the HTML file:
• Before you begin You must download the framework on the official site (http://angularjs.org/), choose
"stable", "Minified" and click Download. Retrieve the file "angular.min. js".
• The line " " will allow you to use AngularJS. TO
Will be active for the tag until the tag < /body>.
The attribute ng-controller in the tag will allow us to define a controller. This controller will be active in the
tag until the tag < /h1 >. Everything that is located between the tags and < /h1> will be submitted to the
You adapt it in the light of the folder which hosts the file "angular.min. js".
"The next line ( " ") will allow us to access
our JavaScript file "ex1.js", here also, attention to the path chosen.
You have probably noticed the attribute ng-app at the level of the body tag. This simply means that AngularJS
번역되고, 잠시 기다려주십시오..