0

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>
Community
  • 1
  • 1
julesrose
  • 47
  • 9
  • I'm not sure whatyou exactly want to do, but if I unerdstood correctly, you want to send data between two controllers, right ? –  Nov 10 '16 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 Nov 10 '16 at 16:01

1 Answers1

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

Prinay Panday
  • 226
  • 2
  • 8