Javascript 角度5将对象传递到组件
因此,我创建了以下类:Javascript 角度5将对象传递到组件,javascript,typescript,angular5,Javascript,Typescript,Angular5,因此,我创建了以下类: 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';
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.logthis.view:[object]
谁能告诉我我做错了什么吗?我想你不需要{{},试试这个[view]=view
<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>