2015-11-25 26 views
4

使用Ng表,我試圖創建一個表視圖,可以從AngularJS參數控制。AngularJS - Ng-表不會分析標題

要控制的標題文字,我需要把它在數據的標題或NG-數據標題(例如:數據標題=「‘測試’」)

但是,它總是讓表頭空。 enter image description here

而是填充它的: enter image description here

代碼段:

<td ng-repeat="v in tableSettings.data" data-title="v.name"> 
    {{v.data?v.data(row):row[v.id]}} 
</td> 

全碼:

<table ng-table="table" class="table" show-filter="{{tableSettings.filter}}"> 
    <tr ng-repeat="row in $data"> 
     <td ng-repeat="v in tableSettings.data" ng-click="tableSettings.click(row)" ng-attr-data-title="'{{v.name}}'" 
      ng-if="v.type!='switch'" 
      sortable="'{{sortable?sortable:v.id}}'"> 
      {{v.data?v.data(row):row[v.id]}} 
     </td> 
    </tr> 
</table 

當我嘗試解析角進去,我只是得到錯誤:(按查看錯誤)

"'{{v.name}}'"             "{{v.name}}"

是有辦法解決它,甚至從AngularJS manualy解析呢?

+0

我不認爲當錯誤發生時您粘貼相關的HTML。 – Arg0n

+0

請嘗試使用'ng-attr-data-title'。 – Arg0n

+0

ng-attr-data-title對錶格沒有任何作用。哪些代碼會更相關? – Amit

回答

4

確定的問題是data-title屬性是指靜態文本(衆所周知列)一起使用,如data-title="'My first column'" 如果你需要的是你必須使用ng-table-dynamic指令動態列。

例如:在指令中聲明

<table ng-table-dynamic="tableParams with cols" show-filter="true" class="table table-bordered table-striped"> 
    <tr ng-repeat="row in $data track by row.id"> 
    <td ng-repeat="col in $columns">{{::row[col.field]}}</td> 
    </tr> 
</table> 

採取通知使用一種特殊的語法tablePramswithcols。這裏cols是一個$scope變量,它必須遵循以下架構才能正常工作。

$scope.cols = [ 
    { title: 'ID', field: 'id', filter: { id : 'text' }, show: true, sortable: 'id' }, 
    { title: 'Installation', field: 'installationAt' }, 
    ... 
]; 

標題和領域是必需的,而filtershowsortable取決於你的使用場景。

可以玩弄這個code pen

+1

這太神奇了!自從我在github「issues」主題上提出這個問題以來,已經過了2個月了。非常感謝! – Amit