ng-template

Angular - ng-template with parameter inside ngIf inside ngFor [duplicate]

帅比萌擦擦* 提交于 2019-12-03 01:09:45
This question already has an answer here: Passing ngFor variable to an ngIf template 3 answers I am trying to build this template: <ul> <li *ngFor='let link of links'> <ng-container *ngIf="link.type == 'complex'; then complexLink else simpleLink"></ng-container> </li> </ul> <ng-template #simpleLink> ... {{ link.some_property }} </ng-template> <ng-template #complexLink> ... {{ link.some_property }} </ng-template> The problem is that the link variable is undefined inside the ng-template so I get an error of accessing 'some_property' of undefined. I am struggeling to understand how I pass the

How to implement a loading spinner with a Angular (5) ng-template?

吃可爱长大的小学妹 提交于 2019-12-02 16:46:50
问题 I've a checkout page where the user has to login before he can proceed. The user can be logged on already. In every scenario I want to show a spinner when the component detects if the users logged in our not. The check-out.html code looks like: <div *ngIf="showSpinner"> <app-spinner></app-spinner> </div> <div *ngIf="auth.user | async; then authenticated else guest"> <!-- template will replace this div --> </div> <!-- User NOT logged in --> <ng-template #guest> <div *ngIf="auth.user == null"

How to implement a loading spinner with a Angular (5) ng-template?

好久不见. 提交于 2019-12-02 07:34:23
I've a checkout page where the user has to login before he can proceed. The user can be logged on already. In every scenario I want to show a spinner when the component detects if the users logged in our not. The check-out.html code looks like: <div *ngIf="showSpinner"> <app-spinner></app-spinner> </div> <div *ngIf="auth.user | async; then authenticated else guest"> <!-- template will replace this div --> </div> <!-- User NOT logged in --> <ng-template #guest> <div *ngIf="auth.user == null" class="call-to-action"> login buttons... </div> </ng-template> <!-- User logged in --> <ng-template

How to dynamically add a cloned node in angular2 (equivalent to cloneNode)

こ雲淡風輕ζ 提交于 2019-12-01 11:13:42
In Angular2, I need to duplicate a node rather than moving it in some cases. That node has angular2 properties so cloneNode doesn't work. How can I do it? *what doesn't work let el = <HTMLElement>document.getElementById(divId); if ((<HTMLElement>el.parentNode).id == 'itsMe') el = <HTMLElement>el.cloneNode(true); document.getElementById(anotherId).appendChild(el); *what would work, from Angular2: Cloning component / HTML element and it's functionality @Component({ selector: 'my-app', template: ` <template #temp> <h1 [ngStyle]="{background: 'green'}">Test</h1> <p *ngIf="bla">Im not visible</p> <

How to dynamically add a cloned node in angular2 (equivalent to cloneNode)

笑着哭i 提交于 2019-12-01 09:08:19
问题 In Angular2, I need to duplicate a node rather than moving it in some cases. That node has angular2 properties so cloneNode doesn't work. How can I do it? *what doesn't work let el = <HTMLElement>document.getElementById(divId); if ((<HTMLElement>el.parentNode).id == 'itsMe') el = <HTMLElement>el.cloneNode(true); document.getElementById(anotherId).appendChild(el); *what would work, from Angular2: Cloning component / HTML element and it's functionality @Component({ selector: 'my-app', template:

What is $implicit in angular 2?

谁都会走 提交于 2019-11-29 01:07:31
How is the following keyword used in angular2 ng-templates What is the purpose of $implicit in angular 2 templates? What is relationship between let-<attribute> and $implicit ? You can define local variable on ng-template through let-name When angular creates template by calling createEmbeddedView it can also pass context that will be used inside ng-template Using the key $implicit in the context object will set it's value as default. So if we write: vcRef.createEmbeddedView(template, { $implicit: 'value' }) and we have template <ng-template let-foo> {{ foo }} </ng-template> then we can think

why *ngIf doesnt'work with ng-template?

拥有回忆 提交于 2019-11-28 22:04:25
问题 I have a condition in the template as follows: <ng-container> <p *ngFor="let seat of InfoDetails?.seatInfo"> <template *ngIf="seat.section"> Section {{seat?.section}} , </template> <template *ngIf="seat.row"> Row {{seat?.row}}, </template> <template *ngIf="seat.seatNo"> Seat number {{seat?.seatNo}} </template> </p> </ng-container> I have dataset that contains row and seatNo , but it does not seem to print in the template. what is the issue here? 回答1: Read the doc here https://angular.io/guide

Passing ngFor variable to an ngIf template

强颜欢笑 提交于 2019-11-27 06:42:56
问题 How do I pass the current variable in an ngFor loop to ngIf, if it is using templates with then/else syntax? It appears that they pass through fine when used inline, but aren't accessible from a template, for example: <ul *ngFor="let number of numbers"> <ng-container *ngIf="number % 2 == 0; then even_tpl; else odd_tpl"><>/ng-container> </ul> <ng-template #odd_tpl> <li>Odd: {{number}}</li> </ng-template> <ng-template #even_tpl> <li>Even: {{number}}</li> </ng-template> The templates don't seem