gpt4 book ai didi

javascript - Angularjs ng-click inside 指令。 ControllerAs 连接问题

转载 作者:行者123 更新时间:2023-11-29 19:13:08 24 4
gpt4 key购买 nike

ShowPopover 在您单击该指令时不起作用。你能帮我找出问题的原因吗?

指令:

 angular.module('landingBuilder').directive('popoverDirective', popoverDirective);

function popoverDirective() {
return {
restrict: 'E',
templateUrl: '/libs/landing-builder/directive/popover-directive/popover-directive.html',
controller: controller,
controllerAs: 'vm',
transclude: true,
bindToController: true
};

function controller($element, $document){
var vm = this;
vm.showPopover = showPopover();
function showPopover() {
console.log('show popover');
};
}
}

模板:

<div class="input-layover popup-target" ng-click="vm.showPopover"</div>

最佳答案

在这里使用 showPopover() 而不是 showPopover

myApp.directive('myDirective', function() {
return {
restrict: 'E',
template: '<button ng-click=vm.showPopover()>hello</button>',
controller: controller,
controllerAs: 'vm',
transclude: true,
bindToController: true
};

function controller($element, $document) {
var vm = this;
vm.showPopover = showPopover;

function showPopover() {
console.log('show popover');
};
}
});

Working Fiddle

关于javascript - Angularjs ng-click inside 指令。 ControllerAs 连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37323960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com