【Angular】ngFor로 Object를 표시시킬 때 Key, Value를 이용하고 싶다
                                            
                                                
                                                
                                                
                                                
                                                
                                                 4140 단어  Angular
                    
소개
이번에는 Object를 ngFor로 표시할 때 KeyValue를 이용하는 방법을 공유해 나간다.
keyvalue 파이프 사용
key-value-example.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
    selector: 'app-key-value-example',
    templateUrl: './key-value-example.component.html',
    styleUrls: ['./key-value-example.component.scss'],
})
export class KeyValueExampleComponent implements OnInit {
    public exampleObject = {
        'イリヤ': '丹下桜',
        'シノブ': '大坪由佳',
        'アカリ': '浅倉杏美',
        'ヨリ': '原紗友里',
        'ミヤコ': '雨宮天',
    };
    constructor() {}
    ngOnInit() {}
}
key-value-example.component.html
<ng-container *ngFor="let chara of exampleObject | keyvalue">
    <div>
        <div>キャラクター名:{{chara.key}}</div>
        <div>声優:{{chara.value}}</div>
    </div>
</ng-container>
이렇게 표시

덧붙여서 Observable의 값이면,
<ng-container *ngFor="let chara of exampleObject | async | keyvalue">
</ng-container>
그렇다면 좋다.
참고
Reference
이 문제에 관하여(【Angular】ngFor로 Object를 표시시킬 때 Key, Value를 이용하고 싶다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/masaks/items/8ca53b5aa06e51e3bd08텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)