N
N
Nikolai Kupstas2017-05-09 11:08:27
Angular
Nikolai Kupstas, 2017-05-09 11:08:27

How to properly pass data to ng-template in Angular?

The task is to write a table component that will support templates.
An example of what I would like to have:

<my-table>
    	<table-column name="Some name"></table-column>
    	<table-column name="Some name2"></table-column>
    	<table-column name="Some name3">
    		<ng-template let-i="item">
    			<a routerLink="/someway/{{i.id}}">Link</a>
    		</ng-template>
    	</table-column>
    </my-table>

I ran into a problem that I don’t really understand how to properly pass data to ng-template. Google was not able to help me much with this problem. Can anyone tell me how to do this correctly or give links to articles that describe how to beat templates in such scenarios?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
ozknemoy, 2017-05-09
@ozknemoy

it is not clear what exactly is needed and why there is a template at all. so only link https://toddmotto.com/angular-ngfor-template-eleme...

L
lega, 2017-05-09
@lega

If the version is A1, then the data is passed (failed) through the prototypes (child scopes), and read access to them must be by name (for writing - through the parent object).
If A2, then you need to transfer through the properties of the components, in A2 there are no built-in templates out of the box.
In your example, there is no ngFor, what data is not being passed?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question