티스토리 뷰
Client Technologies/Angular
Angular : if-else 구조적 Directive template 몇 개
Korean Eagle 2020. 6. 9. 14:39728x90
1. StackOverflow에서 다 나오지만 나중에 참고하기 쉽게 붙여 놓는다.
2. ngSwitch - 특정한 값에 따른 분기만 가능하다.
<!-- foo = 3 -->
<div [ngSwitch]="foo">
<div *ngSwitchCase="1">First Number</div>
<div *ngSwitchCase="2">Second Number</div>
<div *ngSwitchCase="3">Third Number</div>
<div *ngSwitchDefault>Other Number</div>
</div>
<!-- foo = 'David' -->
<div [ngSwitch]="foo">
<div *ngSwitchCase="'Daniel'">Daniel String</div>
<div *ngSwitchCase="'David'">David String</div>
<div *ngSwitchCase="'Alex'">Alex String</div>
<div *ngSwitchDefault>Other String</div>
</div>
4. 멀티플 if - 가장 일반적으로 많이 사용하는 구조이다.
<!-- foo = 5 -->
<ng-container *ngIf="foo >= 1 && foo <= 3; then t13"></ng-container>
<ng-container *ngIf="foo >= 4 && foo <= 6; then t46"></ng-container>
<ng-container *ngIf="foo >= 7; then t7"></ng-container>
<!-- If Statement -->
<ng-template #t13>
Template for foo between 1 and 3
</ng-template>
<!-- If Else Statement -->
<ng-template #t46>
Template for foo between 4 and 6
</ng-template>
<!-- Else Statement -->
<ng-template #t7>
Template for foo greater than 7
</ng-template>
<!-- switch처럼 활용할 경우 -->
<!-- foo = 3 -->
<ng-template [ngIf]="foo === 1">First Number</ng-template>
<ng-template [ngIf]="foo === 2">Second Number</ng-template>
<ng-template [ngIf]="foo === 3">Third Number</ng-template>
<!-- foo = 'David' -->
<ng-template [ngIf]="foo === 'Alex'">Alex String</ng-template>
<ng-template [ngIf]="foo === 'David'">David String</ng-template>
<ng-template [ngIf]="foo === 'Daniel'">Daniel String</ng-template>
출처는 아래의 링크이다.
*ngIf else if in template
How would I have multiple cases in an *ngIf statement? I'm used to Vue or Angular 1 with having an if, else if, and else, but it seems like Angular 4 only has a true (if) and false (else) condition.
stackoverflow.com
728x90
'Client Technologies > Angular' 카테고리의 다른 글
Angular : Custom Structural(구조적) Directive 생성하기 (0) | 2020.06.10 |
---|---|
Angular : Custom Attribute(속성) Directive 생성하기 (0) | 2020.06.09 |
Angular : Pagenation 구현하기 (0) | 2020.06.09 |
Angular : Custom Pipe (0) | 2020.06.09 |
Angular : 유용한 Pipes (0) | 2020.06.09 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
- 도커 개발환경 참고
- AWS ARN 구조
- Immuability에 관한 설명
- 자바스크립트 멀티 비동기 함수 호출 참고
- WSDL 참고
- SOAP 컨슈머 참고
- MySql dump 사용법
- AWS Lambda with Addon
- NFC 드라이버 linux 설치
- electron IPC
- mifare classic 강의
- go module 관련 상세한 정보
- C 메모리 찍어보기
- C++ Addon 마이그레이션
- JAX WS Header 관련 stackoverflow
- SOAP Custom Header 설정 참고
- SOAP Custom Header
- SOAP BindingProvider
- dispatcher 사용하여 설정
- vagrant kvm으로 사용하기
- git fork, pull request to the …
- vagrant libvirt bridge network
- python, js의 async, await의 차이
- go JSON struct 생성
- Netflix Kinesis 활용 분석
- docker credential problem
- private subnet에서 outbound IP 확…
- 안드로이드 coroutine
- kotlin with, apply, also 등
- 안드로이드 초기로딩이 안되는 경우
- navigation 데이터 보내기
- 레이스 컨디션 navController
- raylib
TAG
- 하이버네이트
- MYSQL
- jsp
- Spring
- 설정하기
- Security
- 자바
- 로그인
- 스프링
- one-to-one
- Validation
- XML
- Many-To-Many
- Rest
- login
- RestTemplate
- 외부파일
- WebMvc
- spring boot
- one-to-many
- 매핑
- Angular
- hibernate
- Spring Security
- 스프링부트
- crud
- 상속
- form
- mapping
- 설정
250x250