我在product.projectId中有id值。
product.projectID中的值:= 45414424 我想在facebook上分享我的页面链接。我如何在下面的场景中绑定project.projectId?
<a class="fb-xfbml-parse-ignore" target="_blank"
href="https://www.facebook.com/sharer/sharer.php?
u=https://stackoverflow.com/questions/45414424/&src=sdkpreparse">
Facebook
</a>
下面的似乎不适用于这种情况。
{{product.projectId}}
Component.ts中的代码:
ngOnInit(): void {
this.sub = this._route.params.subscribe(
params => {
let id = +params['id'];
this.getProduct(id);
});
}
ngOnDestroy() {
this.sub.unsubscribe();
}
getProduct(id: number) {
this._productService.getProject(id).subscribe(
product => this.product = product,
error => this.errorMessage = <any>error);
}
服务代码:
getProjects(): Observable<IProject[]> {
return this._http.get(this._projectUrl)
.map((response: Response) => <IProject[]> response.json())
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
getProject(id: number): Observable<IProject> {
return this.getProjects()
.map((products: IProject[]) => products.find(p => p.projectId === id));
}
private handleError(error: Response) {
console.error(error);
return Observable.throw(error.json().error || 'Server error');
}
项目界面
export interface IProject {
projectId: number;
projectName: string;
projectBy: string;
projectDescrition: string;
}