angularjs $scope.$watch(),监听值得变化

时间:2023-03-09 17:30:54
angularjs $scope.$watch(),监听值得变化
myApp.controller('firstController',function($scope,$interval){
$scope.date = new Date();
setInterval(function(){
$scope.$apply(function(){
$scope.date = new Date();
})
},1000) $scope.count = 0;
$scope.$watch("date",function(newValue,oldValue){
++$scope.count;
if($scope.count>5){
//alert("超过五次了")
}
})

  $scope.$wach("name",function(newValue,oldValue){})