javascript - How to share component methods to child? -
i've got 2 components:
<cmp-one></cmp-one>
inserted dom, while i'm using $compile
create <cmp-top>
. in cmptop
controller need <cmp-one>
, insert <cmp-top>
.
insertion works fine, need access cmptop
controller methods cmpone
- , can't figure out how.
what i've tried far adding require: {cmptop: '^^'}
- not working since there no parent component before insertion done.
so, how can achieve this? mean - insert component another, , share methods added child.
updated
here plunker: http://plnkr.co/edit/mgwc5mbh5qid5q5elddq?p=info
so, need access panelcontroller
's methods dialogcomponentcontroller
.
or, maybe i'm doing wrong - please give me clue how make properly.
you can use common service communicate between them (as playerone mentioned).
app.controller('maincontroller', function($scope, menuselection) { $scope.menuselection = menuselection; // retrieve settings object service method , bring scope // whenever 1 sets $scope.menuselection.selected = "object 2", update value in other controller (and vice-versa) }); app.controller('secondcontroller', function($scope, menuselection) { $scope.menuselection = menuselection; // retrieve settings object service method , bring scope }); app.factory('menuselection', function() { var settings = {}; settings.selected = 'object 1'; // default return settings; });
you can point $scope.menuselection.myfoofunction = ...
function in 1 directive , call another.
Comments
Post a Comment