Last active
July 16, 2020 19:13
-
-
Save MacoChave/6732bddd3a25d3833c69d3dde8d3ebca to your computer and use it in GitHub Desktop.
Condicionales y plantillas en angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>App Component</h1> | |
<!-- [atributo] -> Atributo modo solo atributo: Toma valor de variable --> | |
<!-- (atributo) -> Atributo modo solo evento: Asigna valor a variable --> | |
<!-- [(atributo)] -> Atributo modo atributo y evento: Toma y Asigna valor a variable --> | |
<input type="text" [(ngModel)]="name" /> | |
<p>{{ name }}</p> | |
<ng-container *ngIf="flag; else empty"> | |
<div class="container"> | |
<h1>Content when <code>flag = true</code></h1> | |
</div> | |
</ng-container> | |
<ng-template #empty> | |
<div class="container"> | |
<h1>Empty. <code>flag = false</code></h1> | |
</div> | |
</ng-template> | |
<button (click)="flag = !flag">Toggle flag</button> | |
<router-outlet></router-outlet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'], | |
}) | |
export class AppComponent { | |
title = 'ngBestPractice'; | |
flag: boolean = true; | |
name: string = 'Name'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment