angular.equals()、angular.extend()、angular.foreach()、angular.fromJson()、angular.identity()等

angular.equals(o1, o2)

解释:参数o1和o2的比较(参数可以为变量、数组、对象)

demo:angular.equals({name:‘xxx‘},{name:‘yyy‘}); //$ false

angular.extend(dst, src)

dst:被扩展的目标 src:扩展的对象

解释:对象的扩展,存在的类型进行值得覆盖,不存在的增加该类型。

demo:

var dst = {name: ‘xxx‘, country: ‘China‘};

var src = {name: ‘yyy‘, age: 10};

angular.extend(dst, src);

结果:dst:Object {name: "yyy", age: 10}

src:Object {name: "yyy", country: "China", age: 10}

angular.forEach(obj, fun(item,index), [context])

obj:对象 fun:迭代函数 item:对象的每一个元素 index:元素的索引值 每个 context:迭代上下文

解释:对象的遍历

返回值:obj;

demo:var obj = {name: ‘xxx‘, country: ‘China‘};

angular.forEach(obj, function (value, key) {

console.log(key + ‘:‘ + value);

});

//$ name:xxx //$ country:China

var array = [‘xxx‘, ‘yyy‘];

angular.forEach(array, function (item, index) {

console.log(index + ‘:‘ + item + ‘ form ‘ + this.country);

}, obj);

//$ 0:xxx form China //$ 1:yyy form China

angular.fromJson(string)

解释:字符串转化为json对象

var json = angular.fromJson(‘{"name":"xxx","age":34}‘); console.log(json); //$ Object {name: "xxx", age: 34}

angular.toJson(json)

解释:json对象转化为字符串。

angular.toJson({name:‘xxx‘}); //$ "{"name":"xxx"}"

angular.toJson({name:‘xxx‘},true);

//$ "{

//$ "name": "xxx"

//$ }"

angular.toJson({name:‘xxx‘},10);

//$ "{

//$ "name": "xxx"

//$ }"

angular.identity(value)

解释:返回参数第一个参数

console.log(angular.identity(‘xxx‘,‘yyy‘)); //$ xxx

angular.isArray(value)

解释:判断是否为数组

angular.isArray(3); //$ false
angular.isArray([]); //$ true
angular.isArray([1, 2, 3]); //$ true
angular.isArray({name: ‘xxx‘}); //$ false

angular.isDate(value)

解释:判断是否为日期

angular.isDate(‘2012-12-02‘); //$ false
angular.isDate(new Date()); //$ true

angular.isDefined(value)、angular.isUndefined(value)

解释:判断是否为defined/undefined类型

angular.isDefined(undefined) //$ false
angular.isDefined([]); //$ true
angular.isUndefined(undefined) //$ true
angular.isUndefined([]); //$ false

angular.isFunction(value)

解释:判断是否为函数

angular.isFunction(function(){}); //$ true
angular.isFunction(3); //$ false

angular.isNumber(value)

解释:是否为数字

angular.isNumber(4); //$ true
angular.isNumber(‘xxx‘); //$ false
angular.isNumber(new Number(4)); //$ false
angular.isNumber(Number(4)); //$ true

angular.isObject(value)

解释:是否为对象类型

angular.isObject(‘xxx‘); //$ false
angular.isObject(null); //$ false
angular.isObject([]); //$ true
angular.isObject(function(){}); //$ false
angular.isObject({name:‘xxx‘}); //$ true

angular.isString(value)

解释:是否为字符串。

angular.isString(4); //$ false
angular.isString(‘xxx‘); //$ true
angular.isString(new String(‘xxx‘)); //$ false
angular.isString(String(‘xxx‘)); //$ true

angular.lowercase(string)、angular.uppercase(string)

解释:将字符串大写-小写转换

var newString = angular.lowercase(‘XXyyZZ‘);
console.log(newString); //$ xxyyzz

angular.noop()

解释:空函数

var flag = false;
flag ? console.log(‘xxx‘) : angular.noop();
时间: 2024-12-27 12:54:30

angular.equals()、angular.extend()、angular.foreach()、angular.fromJson()、angular.identity()等的相关文章

Angular - - angular.equals

angular.equals 对比两个对象/值是否相等.支持值类型.正则表达式.数组和对象. 如果下列至少有一个是正确的,则将两个对象/值视为相等. 两个对象/值能通过===比较. 两个对象/值是同一类型/他们的属性一致并且通过angular.equals详细比较. 两者都是NaN. (在javascript中, NaN == NaN => false. 但是我们认为两个 NaN 是平等的) 两个值都代表相同的正则表达式 (在JavaScript里, /abc/ == /abc/ => fal

angular的跨域(angular百度下拉提示模拟)和angular选项卡

1.angular中$http的服务: $http.get(url,{params:{参数}}).success().error(); $http.post(url,{params:{参数}}).success().error(); $http.jsonp(url,{params:{wd:'',cb:'JSON_CALLBACK'}}).success().error(); 注意jsonp中cb在angular中规定只能使用JSON_CALLBAC $watch(谁,做什么,false): 谁指

【Angular JS】正确调用JQuery与Angular JS脚本 - 修复Warning: Tired to load angular more than once

自己正在做一个小网站,使用Angular JS + Express JS + Mongo DB,在开发过程中,遇到一些问题,所以整理出来.希望对大家都有帮助. 这是今天解决的一个问题,Angular JS抛出Warning: Tired to load angular more than once. 前端使用的就是Angular JS,同时前端脚本中我也使用了JQuery.以下是二者Script的最初调用顺序, 在public文件夹下的index.html中: 1 <body ng-view>

[Angular Directive] Create a Template Storage Service in Angular 2

You need to define a <template> to be able to use it elsewhere in your app as a TemplateRef. You can store these TemplateRefs in a Service and then access them from any @Directive or @Component in your app. We want to create a service and a componen

野兽的Angular Api 学习、翻译及理解 - - ngRoute Angular自带的路由

野兽的ng api学习 -- ngRoute ngRoute $routeProvider 配置路由的时候使用. 方法: when(path,route); 在$route服务里添加一个新的路由. path:该路由的路径. route:路由映射信息. controller:字符串或函数,指定控制器. controllerAs:一个用于控制器的标识符名称.. template:字符串或函数,html模板. templateUrl:字符串或函数,html模板的地址. resolve:对象,一个可选的

[Angular + Unit Testing] Mock HTTP Requests made with Angular’s HttpClient in Unit Tests

In a proper unit test we want to isolate external dependencies as much as possible to guarantee a reliable test outcome. Http calls represent such external dependencies. Therefore, when testing our Angular components or services that rely on data ret

[Angular] Extract Implementation Details of ngrx from an Angular Application with the Facade Pattern

Extracting away the implementation details of ngrx from your components using the facade pattern creates some interesting possibilities in terms of iteratively migrating an application to ngrx. By decoupling your components from ngrx completely, this

Angular从0到1:function(上)

1.前言 Angular作为最流行的前端MV*框架,在WEB开发中占据了重要的地位.接下来,我们就一步一步从官方api结合实践过程,来学习一下这个强大的框架吧. Note:每个function描述标题之后的★标明了该function的重要程度(1~5星). 2.function(上) Angular封装了一系列公共方法,帮助我们更简单的使用JS.这些就是Angular的function. 2.1.angular.bind(★) angular.bind类似于Function.prototype.

angularjs笔记二

9.ng-repeat ng-repeat 指令用在一个对象数组上 比如: <div ng-app="" ng-init="names=[{name:'Jani',country:'Norway'}, {name:'Hege',country:'Sweden'},{name:'Kai',country:'Denmark'}]"> <p>循环对象:</p> <ul> <li ng-repeat="x in