0

The Angular Material Toolbar is declared like this:

@Component({
  selector: 'mat-toolbar',
  exportAs: 'matToolbar',
  templateUrl: 'toolbar.html',
  styleUrls: ['toolbar.css'],
  inputs: ['color'],
...

})

Is using inputs: ['color] in the component declaration the same as putting @Input() color in the class body?

Also anyone know what the purpose of exportAs is?

4
  • Check out the docs: angular.io/api/core/Directive Commented Oct 20, 2020 at 21:18
  • I did but it's so generic ... for example for exportAs it says: Defines the name that can be used in the template to assign this directive to a variable. Commented Oct 20, 2020 at 21:25
  • There are examples on that page, too. Commented Oct 20, 2020 at 21:28
  • OK - I looked at the export as example and it looks like it allows us to take what would be an element / component directive and turn it into an attribute directive, IIUC. So for example if we wanted to take a div and turn it into a mat-toolbar component we could do <div matToolbar ...> essentially upgrading a div element to a mat-toolbar component? I assume the div then also gets properties like color etc? Commented Oct 20, 2020 at 21:37

1 Answer 1

1

exportAs: 'matToolbar' allows you to make use of your toolbar in the template. example:

<mat-toolbar #myToolbarReference="matToolbar">
...
</mat-toolbar>
{{myToolbarReference.color}}

this property says that the component instance (here MatToolbarComponent instance) could be exported from this element via matToolbar string.

Sign up to request clarification or add additional context in comments.

2 Comments

Cool - I was always wondering why they assigned the tag to a value like that. Any thoughts on the input part?
inputs is the same as marking all the inputs with @Input decorator

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.