2016-06-25 9 views
0

私はtypescriptですでフォームエクスポートクラスに来ている条件値を取得しようとしているが、それは私の[オブジェクト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] –

関連する問題