2017-02-21 3 views
1

내 angular2 앱에 MDL 스테퍼 요소가 있습니다. div 안에이 요소가 있습니다. *ngIf을 적용하고 해당 div에 조건을 적용하면 스테퍼 구성 요소가 완전히 손상됩니다. *ngIf 없이는 완벽하게 표현됩니다.Angular2 ngIf 나누기 요소 스타일

<!-- stepper in context --> 
<div align="center"> 
    <ul class="mdl-stepper mdl-stepper--horizontal" id="demo-stepper-nonlinear"> 
     <li class="mdl-step"> 
      <span class="mdl-step__label"> 
       <span class="mdl-step__title"> 
        <span class="mdl-step__title-text">Checkboxes</span> 
        <span class="mdl-step__title-message">Few quick questions</span> 
       </span> 
      </span> 
      <div class="mdl-step__content"> 

      </div> 
      <div class="mdl-step__actions"> 

      </div> 
     </li> 
     </ul> 
     </div> 

왜 그렇습니까? ngIf없이

Without ngIf

With ngIf

UPDATE ngIf으로 :

<div align="center" *ngIf="stepper"> 
    <ul class="mdl-stepper mdl-stepper--horizontal" id="demo-stepper-nonlinear"> 
     <li class="mdl-step"> 
... 
    </li> 
</ul> 
</div> 

구성 요소 :

export class HomeComponent implements OnInit { 

    stepper: boolean; 
    constructor(){} 
    showContext(){ 
     this.stepper=true; <= To make the div visible 
     ... 
    } 
내 각-cli.json에서 6,

:

"styles": [ 
     "styles.css", 
     "../node_modules/material-design-lite/dist/material.amber-deep_orange.min.css", 
     "../node_modules/mdl-stepper/stepper.css" 
     ], 
     "scripts": [ 
     "../node_modules/material-design-lite/material.min.js", 
     "../node_modules/mdl-stepper/stepper.min.js" 
     ], 
+0

당신이 코드가 * ngIf와 같은 외모와 무엇 무엇을 보여줄 수있는 뭔가를해야한다고 생각 조건? –

+0

CSS/LESS 또는 SASS 코드를 추가 할 수 있습니까? –

+0

'* ngIf' 표현식이 true가 된 후에 다시 upgradeDom()을 실행하고 그 요소들을 DOM에 추가 할 필요가있을 것입니다. http://stackoverflow.com/questions/34421919/integrating-material-design-lite-with-angular2 –

답변

1

난 당신이

<ul #stepper class="mdl-stepper mdl-stepper--hor 
@ViewChild('stepper') stepper:ElementRef; 

constructor(private elRef:ElementRef, private cdRef:ChangeDetectorRef) {} 

showContext(){ 
    this.stepper=true; <= To make the div visible 
    this.cdRef.detectChanges(); 
    componentHandler.upgradeElement(elRef.nativeElement); 
    // or 
    componentHandler.upgradeElement(stepper.nativeElement);   
    ... 
} 
+0

알았습니다. 저는 이것을 시도했지만 실제로 아무것도하지 않았습니다. nativeElement 이외의 다른 것이 필요합니까? – Nitish

+0

답을 업데이트했습니다. 아마도'upgradeElement()'를 정확한 요소에 적용해야 할 것입니다. 나는 MDL을 모른다. 주석에 링크 된 다른 대답에서 언급 한 것처럼'upgradeDom()'을 시도해 볼 수도 있습니다. –

+1

예,이 기능이 작동했습니다. 다시 한 번 감사드립니다 :) – Nitish

관련 문제