angularjs styleguide에서 "컨트롤러 as"사용법을 따라보기에서 호출 할 수있는 기능이있는 컨트롤러를 만듭니다 (예 : ng-if
). 그러나 내가이 함수를 호출했을 때 3 번 호출 된 것처럼 보이지만 어떻게되었는지는 모른다. 여기ControllerAs 패턴이있는 함수가 여러 번 호출되었습니다
(function() {
angular.module('app', []);
function test() {
console.log('init');
var vm = this;
vm.title = "test title";
vm.called = function() {
console.log('get called');
}
}
angular
.module('app')
.controller('test', test);
})();
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div ng-controller="test as vm">
{{ vm.title }} {{ vm.called(); }}
</div>
</body>
</html>
매우 명확한 답변입니다! 감사! –