I am using angular js. I have created a directive as shown below.
HTML
<table data-ng-table="tableParams">
<tr data-ng-repeat="folder in $data">
<td data-title="'Template'" data-sortable="'TemplateName'">
<div
data-my-directive=""
data-templatename="{{folder.TemplateName}}"
data-changeFunction="changeAbc(folder)"
data-saveFunction="saveAbc(folder)"
data-cancelFunction="cancelAbc(folder)"
/>
</td>
</tr>
</table>
Above html is a part of <div data-ng-controller="GridController" />
and the controller will have functions
- changeAbc
- saveAbc
- cancelAbc
and if say I have another controller xyzController
i shall have functions like
- changeXyz
- saveXyz
- cancelXyz
Directive
angular.module('folderSettingApp')
.directive('myDirective', function () {
return {
restrict: 'A'
, templateUrl: '/Scripts/App/Templates/Template.htm'
, replace: true
, link: function ($scope, element, attrs) {
attrs.$observe('templatename', function (value) {
element.find('name').text(value);
});
}
};
});
Some how I need a way to send the names of the save and cancel functions to the directive and then use those names in the data-ng-click
of the below input button.
This is because I then can use this directive with multiple controller.
Template
<template-holder>
<name></name>
<input
type="button"
value="save"
data-ng-click="use-the-function-name-defined-in-the-html-of-controller"
/>
</template-holder>
I am not sure if this is possible. Any help will be appreciated.