I have 3 directives, "parenta", "parentb", and "childb". "parenta" and "parentb" are siblings, while "childb" is a direct child of "parentb".
I am trying to call a controller method from "parenta", however it is not working. For some strange reason, trying to call a method on "childb" controller FROM "parenta" is working instead. What is happening?
var mod = angular.module("app", []);
mod.directive("parenta", function () {
return {
template: "<section><div ng-click='vm.a()'>Rendered by a</div></section>",
replace: false,
controllerAs: "vm",
controller: function () {
this.a = function () {
console.log("a called!");
}
}
}
})
mod.directive("parentb", function () {
return {
template: "<childb></childb>",
replace: false
}
})
mod.directive("childb", function () {
return {
template: "<section><div ng-click='vm.b()'>Rendered by b</div></section>",
replace: false,
controllerAs: "vm",
controller: function () {
this.b = function () {
console.log("b called!");
}
}
}
})
Html:
<div ng-app="app">
<parenta></parenta>
<parentb></parentb>
</div>
Codepen: http://codepen.io/anon/pen/pJMpVe