Im trying to send a message from within a directive to its parent controller (without success)
Here is my HTML
$broadcast
, $emit
, and $on
are deprecatedUse of the scope/rootScope event bus is deprecated and will make migration to Angular 2+ more difficult.
To facilitate making the transition to Angular 2+ easier, AngularJS 1.5 introduced components:
app.component("myElem", {
bindings: {
onGo: '&',
},
template: `
`,
controller: function() {
this.go = (event,data) => {
this.onGo({$event: event, $data: data});
};
}
});
Usage:
angular.module('app', [])
.controller ('Ctrl', function () {
this.go = (data) => {
console.log(data);
this.update = data;
};
})
.component("myElem", {
bindings: {
onGo: '&',
},
template: `
`,
controller: function() {
this.nr = 10;
this.go = (event,data) => {
this.onGo({$event: event, $data: data});
};
}
})
update={{$ctrl.update}}
For more information, see
- AngularJS Developer Guide - Component-based application architecture