$rootscope 根作用域 相当于一个闭包下的一个全局变量
关于一个代码压缩的相关问题;
app.controller('firstFn',[['$scope'],function($s){
$s.name='张三';
}])
app 关于run 方法
app.run 全局方法, 初始化一个全局的数据
app.run(['$rootScope',function($rootScope){
$rootScope.sex='男'
}])
app 关于apply 方法 传播model的变话 ng-click自动变化 ;$timeout 内置的方法相当于setTimeout 也不需要传递apply 方法
app.controller('fist',function($scope){
setTimeout(function(){
$scope.apply(function(){
$scope.name='1111';
})
},1000)
$scope.show=function(){
alert(121212)
}
})
$watch 监听事件
app.controller('fistr',function($ccope){
$scopec.phone={
num:3,
price:1,
fire:0
}
$scope.sum=function(){
return $scope.phone.num*$scope.phone.price;
}
$scope.$watch($scope.sum,function(newValue,oldValue){
$scope.iphone.fire=newValue>=100?0:10
})
})
关于一个代码压缩的相关问题;
app.controller('firstFn',[['$scope'],function($s){
$s.name='张三';
}])
app 关于run 方法
app.run 全局方法, 初始化一个全局的数据
app.run(['$rootScope',function($rootScope){
$rootScope.sex='男'
}])
app 关于apply 方法 传播model的变话 ng-click自动变化 ;$timeout 内置的方法相当于setTimeout 也不需要传递apply 方法
app.controller('fist',function($scope){
setTimeout(function(){
$scope.apply(function(){
$scope.name='1111';
})
},1000)
$scope.show=function(){
alert(121212)
}
})
$watch 监听事件
app.controller('fistr',function($ccope){
$scopec.phone={
num:3,
price:1,
fire:0
}
$scope.sum=function(){
return $scope.phone.num*$scope.phone.price;
}
$scope.$watch($scope.sum,function(newValue,oldValue){
$scope.iphone.fire=newValue>=100?0:10
})
})