Reputation: 1397
I've got a controller made and I'm trying to move the data that is currently in it (was there for testing) out of the controller and im creating a factory so I can do api calls and such for the data when I get around to it.
I'm new to using both AngularJS and ionic an im not sure where the issue lies.
I'm currently getting this error:
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="">
My factory
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' },
]
};
}]);
My controller
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;
}]);
The controllers and factories are included in he 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>
And their defined in the angular.module from the base app.js
gomo = angular.module('gomo', ['ionic', 'gomo.factories', 'gomo.controllers']);
Upvotes: 0
Views: 384
Reputation: 1380
I think your factory may be off. I might try:
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;
}]);
and then in your controller something like:
$scope.history = BookingsHistoryFctry.booking.history();
Upvotes: 0