错误:[$ injector:unpr]

时间:2014-10-14 08:03:34

标签: angularjs

我想使用routeProvider,但是 当我这样使用时,我得到了一个“错误:unpr”:

angular.module('xPlat.app', ['ngRoute'])
.config(function ($routeProvider) {
    $routeProvider
    .when('/item', {
        templateUrl: 'item.html',
        controller: 'ItemCtrl'
    })
    .when('/posItem', {
        templateUrl: 'posItem.html',
        controller: 'POSitemController'
    })
})

这是我的注册模块:

(function () {
    'use strict';
    angular.module('xPlat', ['xPlat.service', 'xPlat.controller', 'xPlat.directives', 'xPlat.repository','xPlat.app']).run(function (DB) {
        DB.init();
    });
    angular.module('xPlat.config', []);
    angular.module('xPlat.directives', []);
    angular.module('xPlat.controller', []);
    angular.module('xPlat.service', []);
    angular.module('xPlat.app', []);
})();

我有2个控制器,但差异文件:

(function () {
    'use strict';
    angular.module("xPlat.controller", ['xPlat.service'])
        .controller('ItemCtrl', function ($scope, itemService) {
            //something todo controller
        });
})();

(function () {
    'use strict';
    angular.module("xPlat.controller", ['xPlat.service'])
        .controller('POSitemController', ['$scope', 'posItemService', 'itemService', function ($scope, posItemService, itemService) {
            //something todo controller
        }]);
})();

这是我的html文件:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <title>Vibrate.POS</title>

    <link href="css/index.css" rel="stylesheet" />    
</head>
<body ng-app="xPlat">
    <a href="#item">Items</a>
    <a href="#posItem">POS Items</a>

    <div ng-view></div>

    <!-- Cordova reference, this is added to your app when it's built. -->
    <script src="cordova.js"></script>
    <script src="scripts/platformOverrides.js"></script>

    <!-- CordovaToDoApp_AngularJS references -->
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular-resource.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-route.js"></script>

    <script src="scripts/index.js"></script>
    <script src="scripts/app.js"></script>
    <script src="scripts/repository.js"></script>
    <script src="scripts/config.js"></script>
    <script src="scripts/directives/directives.js"></script>
    <script src="scripts/services/itemService.js"></script>
    <script src="scripts/services/POSitemService.js"></script>
    <script src="scripts/controllers/itemController.js"></script>
    <script src="scripts/controllers/POSitemController.js"></script>

</body>
</html>

如何解决此问题?

0 个答案:

没有答案