EDIT I was searching for something like this. Combined with suggestions on this post I am now using a binding combined with an expression.
<my-component data="{{data}}">{{data}}</my-component>
Is it possible to pass a controller scope via data binding? My processing controller should get the scope like this:
bindings: {
scope: '<'
}
I want to pass a directive with data from the first controller, and this information should be shown in my new component.. First controller has data, and I want to pass it in the template like this:
<my-component>{{scope.data}}</my-component>
-
I'm not sure whatyou exactly want to do, but if I unerdstood correctly, you want to send data between two controllers, right ?user4676340– user46763402016年11月10日 15:15:53 +00:00Commented Nov 10, 2016 at 15:15
-
If your using sharing universal data, it should reside in a service which is a singleton pointing to the same data state within the context of the app. With properly architected code, controllers are not in the business of 'serving' data to one another. Once you have the service in place you merely inject it into the whatever client controller needs access to the same data.MoMo– MoMo2016年11月10日 16:01:28 +00:00Commented Nov 10, 2016 at 16:01
1 Answer 1
Why do you want to pass the controller's entire scope?
Usually you would pass through an object to the component from the first controller with something like below:
bindings: {
someVariable: '='
}
And then in the html of the controller you would call the component:
<my-component some-variable="scope.someVariable"></my-component>
scope.someVariable would be an object that belongs to the first controller and now you have access to this data inside your component