2017-05-26 124 views
0

我希望做一個表,基於此模型(材料設計精簡版):表複選框和NG-重複(角JS)

https://getmdl.io/components/index.html#tables-section

在我的代碼,我有一個列表,我嘗試以顯示它,以下面的方式,用NG-重複:

    <table class="mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--2dp"> 
         <thead> 
         <tr> 
          <th class="mdl-data-table__cell--non-numeric">Id. administrateurs</th> 
         </tr> 
         </thead> 
         <tbody> 
         <tr ng-repeat="admin in listAdmins"> 
          <td class="mdl-data-table__cell--non-numeric" ng-model="adminselected">{{admin}}</td> 
         </tr> 
         </tbody> 
        </table>  

但結果並不比圖中例子一樣:Admin list

正如我們所看到的,左側沒有複選框,我不明白爲什麼。

另外,如何製作一個表格,我們可以在其中直接添加數據呢?

事實上,與固定列表,它的工作原理。但是,我是通過數據庫中的請求生成的,其值可以更改。我的listadmin在開始時是空的,並且通過驗證過程完成。

+0

您可以使用角度[ui-grid.info] – AMahajan

回答

0

您的代碼正常工作。

<html ng-app="myApp"> 
    <head> 
    <!-- Material Design Lite --> 
    <script src="https://code.getmdl.io/1.3.0/material.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.js"></script> 

    <link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css"> 
    <!-- Material Design icon font --> 
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> 
    <script> 
     angular.module('myApp', []).controller('MainController', ['$scope', function($scope){ 
     $scope.listAdmins = ['admin1', 'admin2', 'admin3']; 
     }]); 
    </script> 
    </head> 
    <body ng-controller="MainController as main"> 
     <table class="mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--2dp"> 
         <thead> 
         <tr> 
          <th class="mdl-data-table__cell--non-numeric">Id. administrateurs</th> 
         </tr> 
         </thead> 
         <tbody> 
         <tr ng-repeat="admin in listAdmins"> 
          <td class="mdl-data-table__cell--non-numeric" ng-model="adminselected">{{admin}}</td> 
         </tr> 

         </tbody> 
        </table>  
    </body> 
</html> 

可能會發生一些錯誤?你能看到瀏覽器控制檯嗎?

+0

它的工作原理,當我在模型中的例子,但與ng-repeat,它不起作用。 我在我的控制檯沒有問題。 –

+0

在編譯角度後得到了什麼html?可能是結果html有一些損壞的標籤? –

+0

我在這個主題上發佈的屏幕。節點/角度編譯後獲得。 –