我定义了以下app.js:离子/科尔多瓦:模块无法找到
angular.module('myApp', ['ionic', 'myApp.controllers'])
.run(function ($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('index', {
url: '/',
templateUrl: 'templates/home.html'
}).state('prints', {
url: '/prints',
templateUrl: 'templates/photo_prints.html'
}).state('box', {
url: '/box',
templateUrl: 'templates/photo_box.html'
}).state('book', {
url: '/book',
templateUrl: 'templates/photo_book.html'
}).state('framed', {
url: '/framed',
templateUrl: 'templates/photo_framed.html'
});
$urlRouterProvider.otherwise("/");
});
这controllers.js:
angular.module('myApp.controllers').controller('HomeController', ['$scope', 'productsFactory', homeController]);
function homeController($scope, productsFactory) {
$scope.products = [];
init();
function init() {
$scope.products = productsFactory.getProducts();
}
}
我也在我的索引添加两个脚本。 HTML:
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<!-- Ionic -->
<link rel="stylesheet" type="text/css" href="lib/ionic/css/ionic.css">
<script type="text/javascript" src="lib/ionic/js/ionic.bundle.js"></script>
<!-- myApp -->
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/factory.js"></script>
<script type="text/javascript" src="js/controllers.js"></script>
</head>
但是当我尝试运行此我得到的错误:
[$injector:nomod] Module 'myApp.controllers' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
我的控制器无法找到......为什么?我实现它完全像来自cordova或离子提供的标准模板。
也许这是一个更好的做法,但它并没有解决问题。 – Mulgard
创建一个plunker,以便我们可以尝试修复它。 – LeftyX
不幸的是我不知道你的意思。我使用'离子启动myApp sidemenu'创建了另一个项目,并使用它。但在我添加了另一个模块后,我遇到了同样的问题。它无法找到。 – Mulgard