2015-12-15 114 views
0

我需要使用,使用匿名函數調用的控制器的指令,顯示在儀表板的兩列一個表,我收到angular.js模塊內部的錯誤:角使用匿名函數

index.html頁面

<!DOCTYPE html> 
<html> 
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular-route.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular-animate.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular-animate.min.js"></script> 


<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular-sanitize.min.js"></script> 

<script type="application/javascript" src="TableView.js"></script> 
    <body ng-app="myNgApp"> 
     <div > 
      <hpdTable></hpdTable> 
     </div> 
    </body> 
</html> 

TableView.js頁

angular.module('myNgApp').directive('hpdTable', TableView); 

function TableView(){ 

     return { 
      restrict: 'E', 
      controller: function ($scope){ 
       $scope.names = [ 
            { 
            "Name": "Security", 
            "Number": "546543254" 
            }, 
            { 
            "Name": "System", 
            "Number": "123456789" 
            }, 
            { 
            "Name": "Cloud", 
            "Number": "9876564321" 
            } 
           ]; 
      }, 
      templateUrl: 'TableView.html' 
    }; 
} 

TableView.html頁

<table> 
    <tr ng-repeat="n in names"> 
    <td>{{ n.Name }}</td> 
    <td>{{ n.Number }}</td> 
    </tr> 
</table> 
</div> 

出了什麼問題?

+0

改爲使用''。 – dipesh

+0

謝謝dipseh,但我仍然收到一個錯誤 未捕獲的錯誤:[$ injector:nomod] http://errors.angularjs.org/1.4.8/$injector/nomod?p0=myNgApp(anonymous function)@ angular。 js:38(匿名函數)@ angular.js:2005b @ angular.js:1929(匿名函數)@ angular.js:2003(匿名函數)@ TableView.js:1 angular.js:38未捕獲錯誤:[$ injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=myNgApp&p1=Error%3A...ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js %3A19%3A463) –

+0

你可以請你用你的代碼做一個plnkr嗎?它有助於重現您的問題。 – robe007

回答

2

如果你的指令被稱爲「hpdTable」,在你的HTML標籤,你應該使用:

<hpd-table></hpd-table> 

該指令的駝峯名字總是與separed「 - 」在HTML標籤。

編輯:

要報告這個錯誤是因爲你需要inicialize您的應用程序模塊。在你的js開頭添加這行代碼

angular.module('myNgApp', []); 
angular.module('myNgApp').directive('hpdTable', TableView); 
+0

仍然不能正常工作...查看錯誤: –

+0

未捕獲錯誤:[$ injector:nomod] http://errors.angularjs.org/1.4.8/$injector/nomod?p0=myNgApp(anonymous function)@ angular。 js:38(匿名函數)@ angular.js:2005b @ angular.js:1929(匿名函數)@ angular.js:2003(匿名函數)@ TableView.js:1 angular.js:38未捕獲錯誤:[$ injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=myNgApp&p1=Error%3A...ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js %3A19%3A463) –

+0

看到我的編輯,也許它會幫助 –