如何使用角度显示“标签”对象的内容?

时间:2019-02-27 22:40:20

标签: javascript angular typescript

如何使用角度显示“标签”对象的内容?

我尝试使用

{{gallery.tags.tag}}

来做到这一点,但是它不起作用

#include <stdio.h>

int main(void) {
  int nr = 5;
  char castChar = (char)nr;
  char realChar = '5';
  printf("The value is: %d\n", realChar);
}

import {IPhoto} from "./iphoto";

export interface IGallery {
  galleryId: string;
  title: string;
  dateCreated: string;
  thumbUrl: string;
  description: string;
  tags?: any;
  photos: IPhoto[];

}

galerry.component.html

export const Galleries = [{
    'galleryId': '1',
    'title': 'Chiny',
    'dateCreated': '2017-11-15T00:00:00+00:00',
    'thumbUrl': './assets/img/gallery/D1.jpg',
    'description': 'Wakacje w Chinach',
    'tags': [{
        'tag': 'Indonezja',
    }, {
        'tag': 'Woda'
    }],

1 个答案:

答案 0 :(得分:1)

您需要*ngFor

<div *ngFor="let gallery of galleries">
    <p><small>{{gallery.dateCreated | polishDate | uppercase}}</small></p>
    <br><small>galleryId: {{gallery.galleryId}}</small>
    <p>des: {{gallery.description}}</p>
    <img src="{{gallery.thumbUrl}}">
    <div>
        <span *ngFor="let tag of gallery.tags">
            {{tag.tag}}
        </span>
    </div>
</div>