3
下面的代碼(也在Plunker)。在控制檯上,我看到多個foo
正在打印。爲什麼這個控制器函數被調用不止一次
<html>
<head>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js'></script>
</head>
<body>
<div ng-app='theApp'>
<div ng-controller='TheController as ctl'>
{{ctl.foo()}}
</div>
</div>
<script>
angular.module('theApp', [])
.controller('TheController', [function() {
this.foo = function() {
console.log('foo');
};
}]);
</script>
</body>
</html>