을 숨길 수 없습니다처럼 보이는 각도 넷 프레임 워크의 구성 요소이Angular4, 내가이 내용
import { ListService } from '../list/list.service';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'view',
template: `
<div *ngIf="row?.id">
<div>
<p>{{row.id}}</p>
<p>{{row.name}}</p>
<p>{{row.weight}}</p>
<p>{{row.symbol}}</p>
</div>
</div>
<div *ngIf="!row">test</div>
<router-outlet></router-outlet>
`,
styles: []
})
export class ViewComponent implements OnInit {
constructor(private route: ActivatedRoute,
private service: ListService) {
this.route.params.subscribe(params => {
const id = parseInt(params['id']);
if (id) {
this.row = this.service.getRow(id);
console.log(this);
}
});
}
row;
ngOnInit() { }
showInfo(){
console.log(this)
}
}
첫 *ngIf="row?.id"
작품을 잘 반면, 두 번째는, 이상한 의미는 항상 true
입니다 작동 내가 뭔가 잘못 한거야?
편집 : 내가 그것을 3 곳 route
, service
및 row
이 console.log
Viewcomponent constructor > after if condition
안에 내가 실행할 때 의미 ViewComponent가 제대로 업데이트되지 않은 것 같다하지만 그것을 테스트
난 기능
showInfo(){
console.log(this)
}
을 만들 때
지금 this
->ViewComponent
은 2 개의 속성 만 있습니다. route
및 service
범위에 문제가 있습니까?
당신이 그것을 거짓으로 기대를? –
아무도 아무 행이나 클릭하지 않으면 false가 될 것이라고 예상합니다. – Viszman