1

I have been trying to implement a template component for some time to fit groups of tr's into a tbody table (templates are the only thing apart from tr's that are acceptable).

Has anyone had luck extending template as a selector for example:

@Component({
selector: 'template [extended]', ...
})

and then in some other component html template to call the component like so?

<template extended></template>

When I try a simple example like above I'm getting Template parse and component on an embedded template errors

2 Answers 2

3

Angular doesn't add <template> elements to the DOM. Also IE doesn't support the <template> tag within <table> or <ul>

I guess attribute directives can help you to achieve what you want (just a guess because I don't know what exactly you try to accomplish)

@Component({
  selector: 'tr[extended]', ...
})

and use it like

<tr extended><tr>
Sign up to request clarification or add additional context in comments.

4 Comments

This does work but I'm trying to implement a set of <tr> rows as one functional unit for user input. When one row is clicked, form elements on the second row shows up using first row's data via *ngIf. Hence trying to wrap them into one component with state
I don't see a way using a component. I guess this should work with a structural directive. They are used with <template> (angular.io/docs/ts/latest/guide/structural-directives.html).
Thanks for that. I ended up going with template. My solution was to implement each set of rows inside template tag, repeating the set with the ngFor directive. State can be saved in one of the rows like so <tr extended #firstRow></tr>... <tr *ngIf="firstRow.something"></tr>
There is also ngForTemplate and ngTemplateOutlet (not sure if they are helpful for what you are doing).
1

The template tag is an inbuilt component, which does not actually render to the view. With it you can for instance circumvent situations where you would need a *ngIf and *ngFor on the same component.

Comments

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.