angularjs 工具方法
生活随笔
收集整理的這篇文章主要介紹了
angularjs 工具方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<!DOCTYPE HTML>
<html ng-app>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
<script src="angular.min.js"></script>
<script>//angular.bind(); -> $.proxy() : 改this指向
function show(n1,n2){alert(n1);alert(n2);alert(this);
}
angular.bind(document,show,3)(4);//改變show函數的this指向,//angular.copy(); //拷貝對象
var a = {name : 'hello'};
var b = {age : '20'};
var c = angular.copy(a,b); //a把所有值覆蓋給了b
console.log(b);//angular.extend(); //對象繼承
var a = {name : 'hello'
};
var b = {age : '20'
};
var c = angular.extend(b,a); //c有
console.log(b);
</script>
</head>
<body>
</body>
</html> <!DOCTYPE HTML>
<html ng-app>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
<script src="jquery-1.11.1.js"></script>
<script src="angular.min.js"></script>
<script>var a = [];
console.log(angular.isArray(a));//是不是數組
window.onload = function(){console.log(angular.isElement( document.body ));console.log(angular.isElement( $(document.body) ));
};console.log(angular.version);
var a = NaN;
var b = NaN;
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 );//this是result
},result);
console.log(result);//JSON.parse() JSON.stringify()
var str = '{"name":"hello","age":"20"}';
var json = angular.fromJson(str);
console.log(json);
var json = {"name":"hello","age":"20"};
var str = angular.toJson(json,true);
console.log( str );
//angular.identity/noopvar str = 'hello';
console.log(angular.identity(str)); //hello
function identity(str){return str;
}
console.log(angular.noop()); //undefined
function noop(){
}
console.log(angular.uppercase('hello'));
</script>
</head><body>
<div id="div1">aaaaaaaa</div>
<script>
var oDiv = document.getElementById('div1');
$('#div1').css('background','red');
//angular.element === $
</script>
</body>
</html> <!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
<script src="angular.min.js"></script>
<script>var m1 = angular.module('myApp1',[]);
var m2 = angular.module('myApp2',[]);m1.controller('Aaa',['$scope',function($scope){//定義Aaa控制器的函數,$scope.name = 'hello';
}]);
m2.controller('Bbb',['$scope',function($scope){$scope.name = 'hi';
}]);document.onclick = function(){var aDiv = document.getElementsByTagName('div');angular.bootstrap(aDiv[0],['myApp1']);angular.bootstrap(aDiv[1],['myApp2']);
};</script>
</head>
<body>
<div ng-controller="Aaa"><p>{{name}}</p>
</div>
<div ng-controller="Bbb"><p>{{name}}</p>
</div>
</body>
</html> <!DOCTYPE HTML>
<html ng-app>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
<script src="angular.min.js"></script>
<script>function Aaa($scope,$timeout){$scope.name = 'hello';setTimeout(function(){//$scope.name = 'hi';$scope.$apply(function(){//$apply針對數據變化有用$scope.name = 'hi';});},2000);$timeout(function(){$scope.name = 'hi';},2000);$scope.show = function(){$scope.name = 'hi';};}</script>
</head><body>
<!--<div ng-controller="Aaa" ng-click="name='hi'">-->
<div ng-controller="Aaa" ng-click="show()"><p>{{name}}</p>
</div></body>
</html> <!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
<script src="angular.min.js"></script>
<script>var m1 = angular.module('myApp',[]);/*m1.controller('Aaa',['$scope',function($scope){//控制器的函數$scope.name = 'hello';
}]);
m1.controller('Bbb',['$scope',function($scope){$scope.name = 'hi';
}]);*/
m1.run(['$rootScope',function($rootScope){ // $rootScope.name = 'hello';
}]);
console.log( m1 );</script>
</head><body>
<div><p>{{name}}</p>
</div></body>
</html>
?
總結
以上是生活随笔為你收集整理的angularjs 工具方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: index作为key是反模式
- 下一篇: HDU(1572),最短路,DFS