EddyG
EddyG

Reputation: 2119

angularjs - Passing scope parameter to component

We can pass scope parameter to a directive

app.directive('appInfo', function() { 
  return { 
    restrict: 'E', 
    scope: { 
      info: '=' 
    }, 
    templateUrl: 'js/directives/appInfo.html' 
  }; 
});

and use it as follows in a view:

<app-info info="app"></app-info>

A component can be used as a directive too:

<component-info></component-info>

But can we pass to it a scope parameter same as info="app" ?

Upvotes: 1

Views: 2289

Answers (1)

Nikolaj Dam Larsen
Nikolaj Dam Larsen

Reputation: 5674

Yes, for a component you'll use bindings instead of scope. So your component definition will look somewhat like this:

app.component('componentInfo', { 
    bindings: { 
        info: '=' 
    },
    // ... and so on
});

Upvotes: 2

Related Questions