2016-06-25 3 views
0

내가 타이프의 형태로 수출 클래스를 오는 조건 값을 얻으려고 노력하지만 나에게 [객체 HTMLDivElement와]typescript에서 동적으로 속성에 값을 바인딩하는 방법 Angular2?

@Component({ 
    template:`<div #noRecordFoundMsg class="ui-widget-header ui-helper-clearfix" 
      style="padding:4px 10px;border-bottom: 0 none;display:{{ displayAttribute }}"> <-----here 
      <span>{{ noRecordFoundMsg }}</span> 
      </div>`}) 



    private displayAttribute: string; 
     exported class Demo{ 
        //some code 
      if (Counts === 0) { 
         this.noRecordFoundMsg = "No Record Found"; 
         this.displayAttribute = "none"; 
        } else { 
         this.displayAttribute = "block"; 
        } 
    } 

답변

2

을 보여주는 dispay 속성 값과 브라우저에서 얻을 수 없습니다입니다, 당신은 시도 [style.display]="displayAttribute" 유무 :

@Component({ 
     template:`<div #noRecordFoundMsg class="ui-widget-header ui-helper-clearfix" 
      [style.display]="displayAttribute" 
    style="padding:4px 10px;border-bottom: 0 none;"> <-----here 
       <span>{{ noRecordFoundMsg }}</span> 
       </div>`}) 
+0

예 해봤 여전히 동일한 문제에 직면 :(에도 또한 [ngStyle] = "{ '디스플레이'displayAttribute}"시도 –

+0

미안이 있어야 '[attr.style.display]' – AngJobs

+0

같은 문제 [개체 HTMLDivElement] –

관련 문제