Error: TypeError: Unable to read property 'libelle of undefined file:
this searche.html
import { Component,OnInit } from "@angular/core";
import { Router,NavigationExtras } from "@angular/router";
import observable = require("data/observable");
import { VoitureService } from "../../voiture/voiture.service";
@Component({
selector: "searche",
moduleId:module.id,
templateUrl: './searche.html',
providers: [VoitureService]
})
export class SearcheComponent {
public constructor(private router:Router,private postsService:VoitureService) {
}
voitures: voiture[];
clients:voiture;
req:string='1';
DT:Date;
idClient:number=0;
refClient:string="";
libelleClient:string;
ngOnInit(){
this.postsService. getPosts(this.req)
.subscribe(results => this.voitures=results );
}
public clicked(IDV:string,LDV:string,RDV:string){
this.postsService. getClient(IDV)
.subscribe(results => this.clients=results );
this.libelleClient=this.clients.libelle;
this.refClient=this.clients.ref;
let navigationExtras: NavigationExtras = {
queryParams:{
libClient: this.libelleClient,
refclient : this.refClient,
}
}
this.router.navigate(["page1"], navigationExtras);
}
}
interface voiture{
id:number;
libelle:string;
ref:string;
}
this searche.html
<stackLayout class="searcheview">
<stackLayout>
<SearchBar class="input" hint="Machine" ></SearchBar>
<ListView [items]="voitures" >
<ng-template let-voiture="item">
<StackLayout rows="auto, auto" columns="*, auto" class="list-group-item" (tap)="clicked(voiture.id,voiture.libelle,voiture.ref)">
<Label text="{{ voiture.id }}" row="0" col="0"></Label>
<Label text="{{ voiture.libelle }}" row="0" col="0"></Label>
<label text="{{ voiture.ref }} " row="1" col="0"></label>
</StackLayout>
</ng-template>
</ListView>
</stackLayout>
</stackLayout>
Whenever the function clicked() is called, an error occurs saying TypeError: Cannot read property 'libelle' of undefined Please assist with a solution.