I have a component "course". I use this component to a list. This list sometimes is horizontal and some times is vertical. Can I choose dynamicaly inside the component the template file?
@Component({
selector: 'course',
templateUrl: getTemplateFile()
})
Something like that would be great feature!
Note Although it's possible for a component to render multiple templates, we recommend using an if:true|false directive to render nested templates conditionally instead. Create multiple HTML files in the component bundle.
There are two types of templates: Static Template. Dynamic Templates.
Angular 2 allows to write multi-line templates by using ` characters to enquote them. It is also possible to put multi-line template into . html file and reference it by templateUrl .
A component controls a patch of screen called a view. It consists of a TypeScript class, an HTML template, and a CSS style sheet. The TypeScript class defines the interaction of the HTML template and the rendered DOM structure, while the style sheet describes its appearance.
I think that this tutorial is very helpful
https://scotch.io/tutorials/component-inheritance-in-angular-2
You can simply extend your base component and overwrite the template. This allows you to have different components with the exact same functionality, but different templates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With