Моего кода до сих пор:вызова функция контроллера, когда директива изменен атрибут
.directive('ngSpreadsheet', function() {
return {
restrict: 'EA',
scope: {
curpart: '='
},
template: '<div id="dataTable" class="dataTable"></div>',
controller: SpreadsheetController,
link: function (scope, element, attrs) {
scope.$watch('curpart', function (val) {
console.log('curpart value changed, new value is: ' + val);
// here i want to call a function of the SpreadsheetController
// or is there a better way, executing stuff when an attribute changed?
});
}
}
})
var SpreadsheetController = (function() {
...
SpreadsheetController.prototype.curPartChanged = function() {
console.debug('curPartChanged');
};
})();
вы должны передать имя функции в качестве атрибута в директиву, используя функцию '&' в директиве http://stackoverflow.com/questions/15991137/calling-method-of-parent-controller-from-a-directive-in-angularjs/15991525 # 15991525 –
нет лучшего способа? Я думаю, что установка связи в моем html - это плохой стиль? – daniel