julesrose julesrose - 28 days ago 6
AngularJS Question

AngularJS Passing Scope via Data Binding

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>

Answer

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