我正在爲我的應用程序構建一個導出函數。我需要有可點擊的按鈕來調用範圍中的導出功能。我試圖用ng-click="myFunction()"
,但出口不叫......Angular not binding ng-click
這裏是我的玉模板
ul.dropdown-menu(role='menu' aria-labelledby='dLabel')
li
a(export-content-as, export-type='markdown',
export-content='properties.quill.getHTML',
href='', ng-click="exportAs()") Export as markdown
li
a(export-content-as, export-type='raw',
export-content='properties.quill.getText',
href='', ng-click="exportAs()") Export as text
li
a(export-content-as, export-type='pdf',
export-content='properties.quill.getContents',
href='', ng-click="exportAs()") Export as PDF
和我的js文件:
angular.module('foo', [])
…
.directive('exportContentAs', ['properties', '$window', 'exportRawText', 'exportMarkdown', 'exportPdf',
function(properties, $window, exportRawText, exportMarkdown, exportPdf) {
function link(scope, element) {
scope.exportAs = function() {
switch (scope.type) {
case 'markdown':
exportMarkdown(scope.exportContent());
break;
case 'raw':
exportRawText(scope.exportContent());
break;
case 'pdf':
exportPdf(scope.exportContent());
break;
default:
break;
}
};
}
return {
scope: {
exportType: '@',
exportContent: '&'
},
link: link,
restrict: 'A'
};
}
]);
我知道模塊加載(我在另一部分代碼中調用另一個指令)。我也知道,當我點擊任何一個鏈接時,函數scope.exportAs是而不是調用。
我也可以設法通過使用element.on('click', exportAs)
來將點擊綁定到exportAs
的調用,但是我想明白爲什麼我需要這樣做(不僅僅是ng-click="exportAs"
)。