Wow ... what a wonderful example ... It took me a while to analyze this ... so I wrote my own (I think, a little more readable) version. I really don't know how to work with Plunker ... so here is the code ... Extract index.html from my file
<div ng-controller='appCtrl as ctrl'> <parent bind-id='ctrl.name'> <child bind-toid='parentCtrlAs.name'></child> </parent> </div>
.Js file
(function () { 'use strict'; var parentComponent = { bindings : { bindId:'=' }, controller : parentCtrl, controllerAs: 'parentCtrlAs', restrict : 'A', transclude : true, templateUrl : 'parent.html', }; var childComponent = { controller : childCtrl, controllerAs: 'childCtrlAs', restrict : 'A', require : { myParent :'^parent' }, templateUrl : 'child.html', }; angular .module('app', []) .controller('appCtrl' , appCtrl) .component('parent' , parentComponent) .component('child' , childComponent); function appCtrl(){ this.name = 'Main..'; } function childCtrl(){ this.$onInit = function() { this.bindToid = this.myParent.name; }; } function parentCtrl(){ this.name = 'Parent Component'; }
}) ();
Hope this helps, Regards, Johnny
source share