julesrose julesrose - 1 year ago 92
AngularJS Question

AngularJS Passing Scope via Data Binding

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:


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download