1

If I have a component with a property of:

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

for instance, and I want to in my view use an async pipe to subscribe to that and use the properties as text, how can you actually subscribe to it? For instance:

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

I am new to Angular2 and not sure if I am doing something wrong or not.

Tomasz Iniewicz
  • 4,379
  • 6
  • 42
  • 47

2 Answers2

2

I believe you were close to a good solution.

<template *ngIf = "model | async as mycar" >
    <p>{{ mycar.make }}</p> 
</template>
0

Try:

<template #mycar = "model | async" >
    <p>{{ (myCar | async).make }}</p> 
</template>
Meir
  • 14,081
  • 4
  • 39
  • 47