I am building an export function for my app in angular. I need to have clickable buttons that would call an export function in the scope. I tried to use ng-click="myFunction()", but the export is not called …
Here is my jade template
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
and my js file :
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'
};
}
]);
I know that the module is loaded (I'm calling another directive in another part of my code). I also know that when I click any of the link, the function scope.exportAs is not called.
I can also manage to bind the click to the call of exportAs by using element.on('click', exportAs), but I would like to understand why I need to do that (on not only ng-click="exportAs").