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){})

posted @ 2016-12-30 15:19  小小强学习网  阅读(2162)  评论(0编辑  收藏  举报