工厂和控制器,未知的提供商

时间:2015-01-07 03:48:03

标签: javascript angularjs ionic-framework

我已经制作了一个控制器,我正在尝试将当前存在的数据(在那里进行测试)移出控制器并创建一个工厂,这样我就可以对数据进行API调用当我绕过它的时候。

我刚开始使用AngularJS和离子,我不确定问题所在。

我目前收到此错误:

Error: [$injector:unpr] Unknown provider: BookingHistoryFctryProvider <- BookingHistoryFctry <- BookingsHistoryCtrl
http://errors.angularjs.org/1.3.6/$injector/unpr?p0=BookingHistoryFctryProvider%20%3C-%20BookingHistoryFctry%20%3C-%20BookingsHistoryCtrl
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:7888:12
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:11806:19
    at Object.getService [as get] (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11953:39)
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:11811:45
    at getService (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11953:39)
    at invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11985:13)
    at Object.instantiate (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12002:27)
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:16255:28
    at chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:622:22
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:40562:28 <div ui-view="">

我的工厂

    gomo_factories.factory('BookingsHistoryFctry', [ function(){
    return function BookingsHistoryFctry(){
        history : [
                { id: 1, date: '17 SEP', time: '14:30' , to: '24 Parramatta Road Leichardt' , from:'34 Enmore road Newtown' , type:'PASSENGER' },
                { id: 2, date: '17 SEP', time: '15:30' , to: '24 Parramatta Road Leichardt' , from:'34 Enmore road Newtown' , type:'DRIVER' },
                { id: 3, date: '17 SEP', time: '16:30' , to: '24 Parramatta Road Leichardt' , from:'34 Enmore road Newtown' , type:'PASSENGER' },
            ]
    };
}]);

我的控制器

    gomo_controllers.controller('BookingsHistoryCtrl',["$scope","BookingHistoryFctry", function($scope, BookingHistoryFctry) {


    /*$scope.history = [
        { id: 1, date: '17 SEP', time: '14:30' , to: '24 Parramatta Road Leichardt' , from:'34 Enmore road Newtown' , type:'PASSENGER' },
        { id: 2, date: '17 SEP', time: '15:30' , to: '24 Parramatta Road Leichardt' , from:'34 Enmore road Newtown' , type:'DRIVER' },
        { id: 3, date: '17 SEP', time: '16:30' , to: '24 Parramatta Road Leichardt' , from:'34 Enmore road Newtown' , type:'PASSENGER' },
    ];*/

    $scope.history = BookingHistoryFctry.history;

}]);

控制器和工厂包含在index.html

   <script type="text/javascript">
  var gomo; // Gomo Application
  var gomo_controllers = angular.module('gomo.controllers', ['ngCordova']); // Gomo Controllers
  var gomo_factories = angular.module('gomo.factories', ['ngCordova']); // Gomo Factories
</script>
<script src="js/app.js"></script>

<!-- Factories -->
<script src="js/factories/bookingsHistoryFctry.js"></script>

<!-- Controllers -->
<script src="js/controllers/bookingsHistoryCtrl.js"></script>

它们在基础app.js

的angular.module中定义
gomo = angular.module('gomo', ['ionic', 'gomo.factories', 'gomo.controllers']);

1 个答案:

答案 0 :(得分:0)

我认为你的工厂可能已关闭。我可能会尝试:

gomo_factories.factory('BookingsHistoryFctry', ['$http', function($http){

      var booking = {};

      booking.history = function() {
            var history = [
                    { id: 1, date: '17 SEP', time: '14:30' , to: '24 Parramatta Road Leichardt' , from:'34 Enmore road Newtown' , type:'PASSENGER' },
                    { id: 2, date: '17 SEP', time: '15:30' , to: '24 Parramatta Road Leichardt' , from:'34 Enmore road Newtown' , type:'DRIVER' },
                    { id: 3, date: '17 SEP', time: '16:30' , to: '24 Parramatta Road Leichardt' , from:'34 Enmore road Newtown' , type:'PASSENGER' },
                ];

            return history;

      }

      return booking;


}]);

然后在您的控制器中,例如:

$scope.history = BookingsHistoryFctry.booking.history();