2017-11-22 3 views
0

compnente 선택기에 조건을 추가 할 수 있습니까? 부여 됨으로써구성 요소 선택기에 조건을 설정할 수 있습니까? 각도 2/4

나는이 간단한 compnenets있는 경우 :

@Component({ 
      selector:'app-first' 
      templateHtml: 'first.html; 
      }) 
export class FirstComponent { 
    check=false; 
} 

둘째 :

먼저

@Component({ 
       selector:'app-second' 
       templateHtml: 'second.html; 
      }) 

을 내 first.html 파일에 내가 설정 이 조건 :

<div *ngIf="check"> 
<app-second></app-second> 
</div> 

항상 두 번째 구성 요소에 어떤 식 으로든로드됩니다.이를 피할 수 있습니까? 그리고 그 이유는 무엇입니까?

감사합니다.

+0

plunker –

답변

0

예 그것은 당신도

<app-second *ngIf="check"></app-second> 

당신이 콘솔에 오류가 있습니까 할 수있는 작품? 이것이 완벽하게 작동해야하기 때문입니다.

+1

코드에 약간의 구문 오류가 있습니다.'* ngif'를'* ngIf'로 대체하십시오. :) –