码迷,mamicode.com
首页 > Web开发 > 详细

AngularJS工具方法

时间:2016-06-01 00:13:18      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

1
2
3
4
var myApp = angular.module(‘myApp‘, []);//ng-app模块化,[]内为依赖的其他模块
myApp.controller(‘Aaa‘, [‘$scope‘, function ($scope) {
    $scope.name = ‘hello‘;
}]);
1
2
3
4
5
6
7
8
function show(n1, n2) {
    alert(n1);
    alert(n2);
    alert(this);
}
angular.bind(document, show, 3)(4);//- > $.proxy():改this指向
angular.bind(document, show, 3, 4)();
angular.bind(document, show)(3, 4);
1
2
3
4
5
6
7
8
9
var a = {
    name: ‘hello‘
};
var b = {
    age: ‘20‘
};
var c = angular.copy(a, b);   //拷贝对象,a把所有值覆盖给了b
console.log(b);
console.log(c);
1
2
3
4
5
6
7
8
9
var a = {
    name: ‘hello‘
};
var b = {
    age: ‘20‘
};
var c = angular.extend(b, a);//对象继承
console.log(b);
console.log(c);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var a = [];
console.log(angular.isArray(a));//判断是否为数组
angular.isArray;
angular.isDate;
angular.isDefined;
angular.isUndefined;
angular.isFunction;
angular.isNumber;
angular.isObject;
angular.isString;
angular.isElement;
 
angular.version;//获取AngularJS版本
 
var a = 1;
var b = 1;
console.log(angular.equals(a, b));//比较,与==稍有不同,
 
var values = [‘a‘, ‘b‘, ‘c‘];
var values = {‘name‘: ‘hello‘, ‘age‘: ‘20‘};
var result = [];
angular.forEach(values, function (value, i) {//第一个参数:值,第二个参数:下标或字段名
    console.log(value);
    console.log(i);
    this.push(value + i);
}, result);//第三个参数为返回值,this为第三个参数
console.log(result);
 
var str = ‘{"name":"hello","age":"20"}‘;
var json = angular.fromJson(str);//相当于原生JSON.parse(),把字符串转化为json
console.log(json);
 
var json = {"name": "hello", "age": "20"};
var str = angular.toJson(json, true);//相当于原生JSON.stringify(),把json转化为字符串,第二个参数为true表示字符串格式化
console.log(str);
 
var str = ‘hello‘;
console.log(angular.identity(str));//输出hello,相当于下面函数,没用
function identity(str) {
    return str;
}
console.log(angular.noop());  //输出undefined,空函数,没用
function noop() {
}
 
angular.lowercase(‘HELLO‘);//转小写
angular.uppercase(‘hello‘);//转大写
 
var oDiv = document.getElementById(‘div1‘);
angular.element(oDiv).css(‘background‘, ‘red‘);





AngularJS工具方法

标签:

原文地址:http://www.cnblogs.com/wayraki/p/5547965.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!