Вот мой компонент детализированного видаНе удается прочитать свойство не определены угловая 2
import {Component,Input,Output,EventEmitter,OnInit} from "@angular/core";
import { Router, ActivatedRoute, Params } from '@angular/router';
import {TypeService} from './type.service'
import { PropertyTypes } from './type';
@Component({
selector:'property-type-view',
template:`
<div class="panel panel-default">
<div class="panel-heading">
<a [routerLink]="['../']"
class="btn btn-success">
<i class="fa fa-list" aria-hidden="true"></i>
</a>
<span class="title">
</span>
</div>
<div class="panel-body">
<div class="row">
{{(PropType | json).name}}
</div>
</div>
</div>
`,
styles:[`
.panel-default>.panel-heading>.title
{
color: #663663;
font-family: Arial, Helvetica, sans-serif;
font-size: 250%;
}
.panel-default>.panel-heading>.btn
{
position: relative;
top: -5px;
margin-left:5px;
}
`]
})
export class TypeViewComponent implements OnInit{
constructor(
private route: ActivatedRoute,
private router: Router,
private service: TypeService) {}
errorMessage: string;
private PropType: PropertyTypes[];
ngOnInit()
{
// (+) converts string 'id' to a number
let id = +this.route.snapshot.params['id'];
this.service.getPropType(id).subscribe(
PropType => this.PropType = PropType,
error => this.errorMessage = <any>error
);
}
}
если я пытаюсь вернуть весь объект {{PropType.name}}
без фильтра трубы я получаю ту же ошибку ниже мой метод обслуживания
getPropType(id:number):Observable <PropertyTypes[]> {
return this.http.get(this.TypeUrl+'/'+id)
.map(res=>res.json())
.catch(this.ThrowError); }
Хотелось бы, чтобы я смог напечатать данные типа свойств с помощью {{PropType.name}}
без сбоев приложения с ошибкой, которую я пробовал. Асинхронная трубка с безопасным оператором, такая как {{(PropType | async)?.name}}
все еще не везет никаких идей?
Я попробовал это раньше и еще не повезло –
Hm ..! Можете ли вы опубликовать свой источник? Я попытаюсь помочь – eugene
Спасибо @cuongngo мне удалось решить проблему, сразу создав собственный PropType: PropertyTypes []; для частного PropType: any = ner PropertyTypes(); –