Marc Rasmussen
Marc Rasmussen

Reputation: 20555

Angular 5 passing object to a component

So i have created the following class:

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

}

And the following component:

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);
    }

}

Now I attempt to insert that through 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>

After debugging I can see if I console.log(this.view) i get: "[object Object]"

Can anyone tell me what I've done wrong?

Upvotes: 0

Views: 2516

Answers (1)

Akhil Aravind
Akhil Aravind

Reputation: 6130

 <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>

Upvotes: 1

Related Questions