2015-05-12 98 views
0

我有3個JS文件在我的申請 (mainApp.js, template.js, app.js定義角模塊在不同的文件

的index.html

<html lang="en" ng-app="myapp"> 

mainApp.js

var app = angular.module('myapp', 
     ['myapp.templateApp', 'myapp.demoApp']); 

template.js

angular.module('myapp.templateApp', ['slick', 'localization']) 
.controller('CountryLaunguageSelection', [ 
    '$scope', '$rootScope','$http', 
    function($scope, $rootScope,$http) { 

    } 
]); 

app.js

var app = angular.module('myapp.demoApp', [ 
       'ui.router', 
       'ui.grid', 
       'ngTouch', 
       'ui.grid.selection', 
       'ui.bootstrap', 
       'ngTable' 
      ]); 

app.config(function($stateProvider, $urlRouterProvider) { 

}); 

我需要的3個模塊將在3個不同的files.Could有人告訴我,什麼是錯的,上面的代碼。

我提示以下錯誤:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.28/$injector/modulerr?p0=app&p1=Error%3A%20…0%2FdemoApp%2Ftemplate%2Fthird-party%2Fangular%2Fangular.min.js%3A18%3A387) 
+0

您確實鏈接了索引文件中的所有文件? – Rouby

+0

是的,我已經鏈接了這些文件。 –

+0

正如Rouby所說的那樣。在注入模塊之前,請將所有js加載到dom中。像。 – Vineet

回答

0

就創造了這樣一個本地主機 - 它的工作原理。嘗試比較你的index.html和依賴關係。

的index.html

<!DOCTYPE html> 
<html lang="en" ng-app="myapp"> 
<head lang="en"> 
    <meta charset="UTF-8"> 
    <script src="angular.min.js"></script> 
    <script src="mainApp.js"></script> 
    <script src="app.js"></script> 
    <script src="template.js"></script> 
</head> 
<body> 
<div ng-controller="CountryLaunguageSelection"> 
    {{data.myData}} 
</div> 
</body> 
</html> 

mainApp.js

var app = angular.module('myapp', ['myapp.templateApp', 'myapp.demoApp']); 

app.js

var app = angular.module('myapp.demoApp', []); 

app.config(function() { 

}); 

template.js

angular.module('myapp.templateApp', []) 
    .controller('CountryLaunguageSelection', [ 
    '$scope', '$rootScope','$http', 
    function($scope, $rootScope, $http) { 
     $scope.data = { 
      myData: "Hello" 
     }; 
    } 
    ]); 
+0

如果您在Linux/MacOS中工作,還要檢查文件的權限。有時需要更改'chown'和/或'chmode' –

相關問題