繁体   English   中英

Angular 5将对象传递到组件

[英]Angular 5 passing object to a component

所以我创建了以下课程:

export class PresentObject {
    public type: string;
    public resourceUrl: string;
    public text: string;

}

和以下组件:

import {Component, Input, OnInit} from '@angular/core';
import {PresentObject} from '../classes/present-object';

@Component({
    selector: 'app-video',
    templateUrl: './video.component.html',
    styleUrls: ['./video.component.css']
})
export class VideoComponent implements OnInit {

    @Input()
    view: PresentObject;

    constructor() {
    }

    ngOnInit() {
        console.log(this.view.text);
    }

}

现在,我尝试通过HTML插入:

  <section *ngFor="let view of views; let last = last" [ngSwitch]="view.type">
    <app-video *ngSwitchCase="'video'" view="{{view}}"></app-video>
  <span *ngIf="last">{{repeatComplete()}}</span>
</section>

调试后,我可以查看是否我console.log(this.view)得到: "[object Object]"

谁能告诉我我做错了什么?

 <section *ngFor="let view of views; let last = last" [ngSwitch]="view.type">
    <app-video *ngSwitchCase="'video'" view="view"></app-video>
  <span *ngIf="last" (click)="repeatComplete()">LAST</span>
</section>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM