AngularJS系列——对象详解
1. angular对象 * 由angular.js提供的全局变量
//手动启动angular应用 angular.bootstrap(document,['myApp']) 2. module对象 * 由angular.module()创建 angular.module('myApp',[])
.factory('fService',function () {
console.log('factory()');
return function () {
console.log('fService()...');
}
})
.service('sService',function () {
console.log('service()');
this.test = function () {
console.log('sService test()');
}
})
.filter('leftTrim',function () {
return function (str) {
return str.replace(/^s+/,'');
}//检查字符串前边是够有空格,有的话去掉
})
.config(function () {
console.log('config()');
//配置路由(后面讲)
})
.controller('MyCtrl',function ($scope,fService,sService) {
console.log('MyCtrl()');
fService();//factory创造的就是函数,传过来的也是函数
sService.test();//构造函数传过来的是对象
$scope.msg = ' atguigu ';
});
3. $scope对象 * $apply(): 强制脏数据检查 var unWatch = $scope.$watch('msg',function (newMsg,oldMsg) { if(newMsg!==oldMsg){ $scope.count++; if($scope.count === 10){ //取消监视 unWatch(); $scope.count = '已达到最大值(10)' } } }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |