1

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" ?

1
  • Yes, of course. Component is just a special case of directive. Commented Mar 24, 2017 at 13:46

1 Answer 1

2

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
});
Sign up to request clarification or add additional context in comments.

3 Comments

How to pass this parameter to the controller?
This will already be available in your controller through 'this.info'.
Thanks. I forgot to add "this" :p

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.