这是我的 app.js
var MyApp = angular.module('MyApp', []);
MyApp.controller('MyController', ['$scope', function($scope){
$scope.watchMe = 'hey';
$scope.init = function() {
setTimeout(function() {
$scope.watchMe = 'changed!';
}, 3000)
};
$scope.$watch('watchMe', function() {
console.log($scope.watchMe)
});
}]);
我想,3秒后,我会看到:
'changed!'
在我的控制台中。
相反,我只看到:
'hey'
我在 index.html 中调用我的 init() 函数,如下所示:
<div ng-controller="MyController" ng-init="init()">
为什么我看到这个输出?