0
votes

My app was working fine, I installed cordova geolocation, but after adding $cordovaGeolocation and $ionicPopup nothing is working, I redid the code a few times and checked and rechecked the spelling, etc.

Here is my error:

Uncaught Error: [$injector:modulerr] Failed to instantiate module caffeinehit due to: Error: [$injector:modulerr] Failed to instantiate module caffeinehit.services due to: Error: [$injector:nomod] Module 'caffeinehit.services' 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.

Top code from app.js:

var app = angular.module('caffeinehit', [
'ionic',
'ngCordova',
'caffeinehit.controllers',
'caffeinehit.services',
'caffeinehit.filters'

]);

services.js Code:

var app = angular.module('caffeinehit.services', []);

app.service("YelpService", function ($q, $http, $cordovaGeolocation, $ionicPopup) {

  var self;
  self = {
    'page': 1,
    'isLoading': false,
    'hasMore': true,
    'results': [],
    'lat': 51.545540,
    'lon': -0.0223374,


    'load': function () {
      self.isLoading = true;
      var deferred = $q.defer();
      ionic.Platform.ready(function () {
        $cordovaGeolocation
          .getCurrentPosition({timeout: 10000, enableHighAccuracy: false})
          .then(function (position) {
            self.lat = position.coords.latitude;
            self.lon = position.coords.longitude;

Later having trouble with adding $ionicPopup:

 }, function (err) {
            console.error("Error getting position");
            console.error(err);
            $ionicPopup.alert({
              'title': 'Please switch on your gps',
              'template': "It seems like you switch off your gps, please turn it on"
            });
2

2 Answers

0
votes

You need to include ionic and cordova in your app module

var app = angular.module('caffeinehit.services', ['ionic', 'ngCordova']);
0
votes

I figured out the issue, once I changed around the order and put $ionicPopup before $cordovaGeolocation in the app module, it worked.