Asynchronous 如何使用异步管道从Angular2组件的视图中使用单个可观察属性?

Asynchronous 如何使用异步管道从Angular2组件的视图中使用单个可观察属性?,asynchronous,typescript,angular,observable,rxjs5,Asynchronous,Typescript,Angular,Observable,Rxjs5,如果我有一个属性为的组件: import { Component, OnInit } from 'angular2/core'; import { CarService } from 'someservice'; @Component({ selector: 'car-detail', templateUrl: './app/cars/car.component.html' }) export class CarComponent implements OnInit {

如果我有一个属性为的组件:

import { Component, OnInit } from 'angular2/core';
import { CarService } from 'someservice';

@Component({
    selector: 'car-detail',
    templateUrl: './app/cars/car.component.html'
})

export class CarComponent implements OnInit {

    model: Observable<Car>;

    constructor(
        private _carService: CarService
    ) { }

    ngOnInit() {
        // begin benefit setup
        this.model = this._carService.get(5);
    }
}
从'angular2/core'导入{Component,OnInit};
从“someservice”导入{CarService};
@组成部分({
选择器:“车辆详细信息”,
templateUrl:“./app/cars/car.component.html”
})
导出类CarComponent实现OnInit{
模型:可观察;
建造师(
私家车服务:私家车服务
) { }
恩戈尼尼特(){
//开始福利设置
this.model=this.\u carService.get(5);
}
}
例如,在我看来,我想使用一个异步管道来订阅它,并将属性用作文本,您如何才能真正订阅它?例如:

<template #mycar = "model | async" >
    <p>{{ myCar?.make }}</p> 
</template>

{{myCar?.make}}

我刚接触Angular2,不确定自己是否做错了什么。

试试:

<template #mycar = "model | async" >
    <p>{{ (myCar | async).make }}</p> 
</template>

{(myCar | async.make}


我相信您已经接近一个好的解决方案


{{mycar.make}}


看起来不错。有什么问题吗?@GünterZöchbauer是的,我知道。。。但它不起作用(你的问题并没有说明
model
是如何分配值的。仅凭上面的代码,什么都没有发生就不足为奇了。@GünterZöchbauer我用完整的组件更新了这篇文章。_carService.get(5)返回了什么?这不会创建两个订阅吗?