Scope and Dependency injection of ANGULARJS

Source: Internet
Author: User

I. Scope of ANGULARJS

<!DOCTYPE HTML><HTMLNg-app><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Angular overview</title><Scriptsrc= "Angular.min.js"></Script><Script>functionAaa ($scope, $rootScope) {//plus $rootscope This can be an age display, the equivalent of a global scope$scope. Name= 'Hello'; $scope. Age= ' +';}functionBBB ($scope) {$scope. Name= 'Hi';}</Script></Head><Body><DivNg-controller= "Aaa">    <P>{{Name}}</P>    <DivNg-controller= "BBB">        <P>{{Name}}</P>        <P>{{Age}}</P>    </Div></Div></Body></HTML>
<!DOCTYPE HTML><HTMLNg-app><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Angular overview</title><Scriptsrc= "Angular.min.js"></Script><Script>functionAaa ($scope, $rootScope) {//plus $rootscope This can be an age display, equivalent to a global$scope. Name= 'Hello'; $scope. Age= ' +'; //$rootScope. Age = ' 20 '; This is the final, if there is no age,aaa under the BBB, then age is equal to this value, if the global is not, then this age is really not}functionBBB ($scope) {$scope. Name= 'Hi'; $scope. Age= ' -'; //This property is also added here, the result is}</Script></Head><Body><DivNg-controller= "Aaa">    <P>{{Name}}</P>        <DivNg-controller= "BBB">        <P>{{Name}}</P>        <P>{{Age}}</P>    </Div></Div></Body></HTML>

Ii. Dependency Injection

<!DOCTYPE HTML><HTMLNg-app><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Untitled Document</title><Scriptsrc= "Angular.min.js"></Script><Script>    functionAaa ($scope, $rootScope) {//The parameters must be such that they cannot be modified.Alert (123); }</Script></Head><Body>    <DivNg-controller= "Aaa">            </Div></Body></HTML>

Scope and Dependency injection of ANGULARJS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.