AngularJS tool methods and using jquery in AngularJS

Source: Internet
Author: User

1. AngularJS tool method, refer to AngularJS API HTTPS://DOCS.ANGULARJS.ORG/API official documentation

(1) Angular.isarray (value) determines whether it is an array, returning TRUE/FALSE

[HTML]View PlainCopy
    1. <div ng-controller="Firstcontroller">{{isarray}}</div>
[HTML]View PlainCopy
    1. $scope.arr=[1,2,3];
    2. $scope.isarray=angular.isarray ($scope. arr);

(2) Angular.isdate (value) determines whether it is a date type and returns True/false

(3) angular.iddefined (value) determines whether or not it is defined and returns True/false

(4) angular.iselement (node) determines if it is a DOM node and returns True/false

(5) Angular.isfunction (value) determines whether it is a function type and returns TRUE/FALSE

(6) Angular.isnumber (value) determines whether the number type, which includes nan,infinity and-infinity, returns True/false

(7) Angular.isobject (value) determines whether it is an object type, array is a OBJCT type, NULL is not an object type, and returns True/false

(8) Angular.isstring (value) determines whether it is a string type and returns True/false

(9) Angular.uppercase (value) converted to uppercase

[HTML]View PlainCopy
    1. <div ng-controller="Firstcontroller">{{name1}}</div>
[HTML]View PlainCopy
    1. $scope.name=' Zhangsan ';
    2. $scope.name1=angular.uppercase ($scope. Name);

(+) Angular.lowercase (value) converted to lowercase

(one) angular.equals (O1,O2) determines whether two strings are equal and returns True/false

[HTML]View PlainCopy
    1. <div ng-controller="Firstcontroller">{{eq}}</div>
[HTML]View PlainCopy
    1. $scope.a=' 111 ';
    2. $scope.b=' 111 ';
    3. $scope.eq=angular.equals ($scope. A, $scope. b);

Angular.extend (DST,SRC) inheritance relationship, as shown in the following code, b inherits the properties of a

[HTML]View PlainCopy
    1. $scope.a={name: ' Zhang San '};
    2. $Scope.b={age:10};
    3. $scope.c=angular.extend ($scope. B, $scope. a);
    4. Console.log ($scope. b);//{"Age": Ten, "Name": "Zhang San"}

Angular.fromjson (JSON) deserializes a JSON string into a JavaScript object

[HTML]View PlainCopy
    1. var json = ' {' name ': ' Hello ', ' age ': ' 20 '} ';
    2. Console.log (JSON);
    3. $scope.json=Angular.fromjson (JSON);
    4. Console.log ($scope. JSON);

Angular.tojson (Obj,pretty) format JSON string

[HTML]View PlainCopy
    1. var json = {"name": "Hello", "Age": "20"};
    2. Console.log (JSON);
    3. $scope.json=Angular.tojson (JSON);
    4. $scope.json=Angular.tojson (json,true);
    5. Console.log ($scope. JSON);


(15) angular. Copy(source, [destination]), as shown in the following code, copies a to B

[HTML]View PlainCopy
    1. $scope.a={name: ' Zhang San '};
    2. $Scope.b={age:10};
    3. $scope.c=angular.copy ($scope. A, $scope. b);
    4. Console.log ($scope. a);
    5. Console.log ($scope. b);


(16) angular. ForEach(obj, iterator, [context])

[HTML]View PlainCopy
    1. var json = {"name": "Hello" , "Age": "A", "sex": ' Male '};  
    2.   
    3. angular.foreach (JSON, function (Val,key) {  
    4.   
    5.       // Console.log (val);   
    6.     console.log (key);   


[HTML]View PlainCopy
    1. var json = {"name": "Hello" , "Age": "A", "sex": ' Male '};  
    2.   
    3. var  RESULTS=[];&NBSP;&NBSP;
    4.   
    5. angular.foreach (Json,function (val,key) {  
    6.     // Console.log (val);   
    7.     //console.log (key);   
    8.     this.push (key+ '---' +val);   
    9. },results)   
    10.   
    11. console.log (results);   


(17) angular. Bind(self, fn, args), binding object, as the context of the function

[HTML]View PlainCopy
    1. var self={name: ' Zhang San '};
    2. var f=Angular.bind (self,function (age) {
    3. $scope.info=this.name+ ' is ' +age;
    4. Console.log ($scope. info);
    5. });
    6. F (30);
    7. var f=Angular.bind (self,function (age) {
    8. $scope.info=this.name+ ' is ' +age;
    9. Console.log ($scope. info);
    10. },10);
    11. f ();

AngularJS tool methods and using jquery in 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.