0
我想在我的代碼中使用$ emit發出指令。
我
(function() {
angular
.module('myApp')
.directive('testDirective', testDirective);
function testDirective() {
var directive = {
link: link,
restrict: 'A',
controller: testCtrl,
controllerAs: 'vm'
};
return directive;
function link(scope, element, attrs) {
}
}
function testCtrl() {
var vm = this;
// do something
vm.$emit('someEvent', {'id': '123'})
}
})();
但是,我得到 'TypeError: vm.$emit is not a function
'。我不知道如何解決這個問題。誰能幫忙?非常感謝!