I'm trying to pass an object to another component.
Request-list.html
<tr [routerLink]="['Request', { id: request.id }]" *ngFor="let request of requests" [req]="request">
<td class=" ">{{ request.datum }}</td>
<td class=" ">{{ request.artist.name }} </td>
<td class=" ">{{ request.artist.user.first_name }}
<td class=" ">{{ request.user.first_name }}</td>
<td class=" ">{{ request.duration.price }}</td>
<td class=" ">{{ request.created_at }}</td>
<td class=" ">{{ request.rejected_at }}</td>
</tr>
RequestListComponent
import {Component} from '@angular/core';
import {Service} from './../services/service.service';
import {Request} from './../classes/request';
import {RouteConfig, ROUTER_DIRECTIVES} from '@angular/router-deprecated';
import {RequestComponent} from './request.component';
@Component({
directives: [ROUTER_DIRECTIVES, RequestComponent],
templateUrl: 'partials/request-list.html'
})
export class RequestListComponent {
requests: Request[];
constructor(private _Service: Service) {}
ngOnInit(){
this._Service.getRequests().subscribe(data => this.requests = data);
}
}
RequestComponent
import {Component, Input} from '@angular/core';
import {Service} from './../services/service.service';
import {Request} from './../classes/request';
@Component({
templateUrl: 'partials/request.html'
})
export class RequestComponent {
@Input() req: Request;
constructor(private _Service: Service) {}
}
However I get the error: "Can't bind to 'req' since it isn't a known native property"
What am I doing wrong?
RequestComponent?RequestComponentis loaded with the router and not inside theRequestListComponent. Because of this, you can not use the@Input()to pass data into theRequestComponent.