Angularjs Tool Method 3

Source: Internet
Author: User

First, angular.version judge the version of Angular
Console.log (angular.version);

Second, angular.equals determine whether two variables are equal
var a = NaN; var b = Nan;console.log (Angular.equals (A, b)        ); // true var x = 1; var y = 1; Console.log (angular.equals (x, y)); var c = []; var d = [];console.log (Angular.equals (c,d));   // Two the same array is equal, and JS is different, JS to determine whether two arrays are equal, based on the address value of the array, two array address value is not the same

three, Angular.foreach traversal function, receive three parameters
    var values = [' A ', ' B ', ' C '];    Angular.foreach (values,function(value,i) {        console.log (value);   // the value        of the array Console.log (i);        // Subscript of the array    });   
 var  values = {' name ': ' Hello ', ' age ': ' }); 
    var values = {' name ': ' Hello ', ' age ': ' + '};     var result = [];   // define an array, add the result to this array the      third parameter in the method is this        // traversing Objects    Angular.foreach (values,function(value,i) {        this. push (i+ "=" + value+ ","  );    },result);            Console.log (result);


The Angular.fromjson/tojson function is to parse the JSON, parse the JSON of the string, and convert the string to JSON .
    var str = ' {' name ': ' Hello ', ' age ': ' "} ';     var json = Angular.fromjson (str);  // parse a string into a true JSON object    Console.log (JSON);
    var json = {"name": "Hello", "Age": "$"};     var str = Angular.tojson (JSON,true);   // The JSON is converted to    a string, the second parameter is true, and  the string is formatted    console.log (str);

v. Angular.identity/noop helper methods, setting default values
    var str = ' Hello ';    Console.log (angular.identity (str));     // The result is Hello        . // The implementation principle of this method, using native JS as follows    function Identity (str) {        return  str;    }
    Console.log (Angular.noop ());  // The result is undefined        . // The principle of implementation is an empty function    function NoOp () {    }

vi. Conversion of angular.lowercase/uppercase and uppercase letters
Console.log (angular.uppercase (' Hello '));    // converted to uppercase.

vii. Angular.element Gets the element, gets the element can carry on the subsequent operation
<!DOCTYPE HTML><HTMLNg-app><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Untitled Document</title><Scriptsrc= "Jquery-1.11.1.js"></Script><Scriptsrc= "Angular.min.js"></Script></Head><Body><DivID= "Div1">Aaaaaaaa</Div><Script>    varOdiv=document.getElementById ('Div1'); //$ (' #div1 '). CSS (' background ', ' red ');angular.element (odiv). CSS ('background','Red'); //angular.element (' #div1 '). CSS (' background ', ' red ');        //Angular.element = = = $//two identity</Script></Body></HTML>

viii. angular.bootstrap dynamic initialization, HTML tags can not write Ng-app use this method for dynamic initialization, the advantage is that when you want to initialize the initialization
<!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Untitled Document</title><Scriptsrc= "Angular.min.js"></Script><Script>    varM1=Angular.module ('MyApp1',[]); varm2=Angular.module ('myApp2',[]); M1.controller ('Aaa',['$scope',function($scope) {$scope. Name= 'Hello';    }]); M2.controller ('BBB',['$scope',function($scope) {$scope. Name= 'Hi';     }]); Document.onclick= function(){              //dynamic initialization when clicking on a page        varAdiv=document.getElementsByTagName ('Div'); Angular.bootstrap (adiv[0],['MyApp1']); Angular.bootstrap (adiv[1],['myApp2']);    }; //initialized by instruction, when the whole is initialized in the HTML tag, but when initializing only one, you can add ng-app= "MuApp1" to the tag that requires initialization, but when there are multiple    //this time only initializes the first one, the following is not initialized, so it is better to use dynamic initialization</Script></Head><Body>    <DivNg-controller= "Aaa">        <P>{{Name}}</P>    </Div>    <DivNg-controller= "BBB">        <P>{{Name}}</P>    </Div></Body></HTML>

Ix. a meaning of the Angular.injector registrar

Angularjs Tool Method 3

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.