Home  >  Article  >  Web Front-end  >  How to use AngularJS API

How to use AngularJS API

php中世界最好的语言
php中世界最好的语言Original
2018-03-20 10:43:071417browse

This time I will show you how to use the API of AngularJS, and what are the precautions for using the API of AngularJS. The following is a practical case, let's take a look.

Basics


angular.

bootstrap() Manually start AngularJSangular.element() Wraps a part of the DOM element or is HTML
String, treat it as a jQuery element. angular.module() Create, register or retrieve AngularJS module

JSON

angular.fromJson() Deserialize JSON string

angular.toJson() Sequence Convert JSON string

Compare

angular.isArray() If the reference is an array, return true

angular.isDate() If the reference is a date, return true
angular.isDefined () If the reference is defined, return true
angular.isElement() If the reference is a DOM element, return true
angular.isFunction() If the reference is a function, return true
angular.isNumber() If the reference Returns true if the reference is a number
angular.isObject() Returns true if the reference is an object
angular.isString() Returns true if the reference is a string
angular.isUndefined() Returns if the reference is undefined true
angular.equals() Returns true if the two objects are equal

Conversion

angular.lowercase() Convert the string to lowercase

angular.uppercase() Convert the character Convert string to uppercase
angular.copy() Deep copy of array or object
angular.forEach() Iteration function of object or array

angular.copy(source,destination) Deep copy

When you need to copy an array or object, if you directly use $scope.user = $scope.master, it will cause linkage between the two parties, so you should use $scope.user = angular.copy($scope.master)

Use You need to pay attention to the following points when doing so:

If there is only one parameter (no copied object is specified), a copy object will be returned

If destination is specified, a deep copy will be made

Object copy To destination

If the source is null or undefined, the source will be returned directly

If the source is the destination, an error will be reported.

angular.forEach() Iteration of objects or arrays

Loop for objects

var values = {name: 'misko', gender: 'male'};var log = [];
angular.forEach(values, function(value, key) { 
  this.push(key + ': ' + value);
}, log);
For arrays of objects

var objs =[{a:1},{a:2}];angular.forEach(objs, function(data,index,array)
{//data等价于array[index]console.log(data.a+'='+array[index].a);});
I believe you have mastered it after reading the case in this article For more exciting methods, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Tips for using max-width and min-width

How to solve the problem of incomplete display of android textinput

The above is the detailed content of How to use AngularJS API. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn