2015-07-06 22 views
5

to co mój plik app.js wygląda następująco:błąd dostawca nieznane regulatora

// Ionic Starter App 

// angular.module is a global place for creating, registering and retrieving Angular modules 
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html) 
// the 2nd parameter is an array of 'requires' 
// 'starter.controllers' is found in controllers.js 
angular.module('starter', ['ionic', 'starter.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) 
    ionic.Platform.fullScreen() 
    if (window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    } 
    if (window.StatusBar) { 
     // org.apache.cordova.statusbar required 
     // StatusBar.styleDefault(); 
     StatusBar.hide(); 
    } 
    }); 
}) 

.config(function($stateProvider, $urlRouterProvider) { 
    $stateProvider 

    .state('app', { 
    url: "/app", 
    abstract: true, 
    templateUrl: "templates/rubyonic/menu.html", 
    controller: 'AppCtrl' 
    }) 

    .state('app.alerts', { 
    url: "/alerts", 
    views: { 
     'menuContent': { 
     templateUrl: "templates/rubyonic/alerts.html" 
     } 
    } 
    }) 

    .state('app.profile', { 
    url: "/profile", 
    views: { 
     'menuContent': { 
     templateUrl: "templates/rubyonic/profile.html" 
     } 
    } 
    }) 

    .state('app.rank-charts', { 
    url: "/rank_charts", 
    views: { 
     'menuContent': { 
     templateUrl: "templates/rubyonic/rank_charts.html" 
     } 
    } 
    }) 

    .state('overview', { 
    url: "/overview", 
    controller: 'OverviewCtrl', 
    templateUrl: "templates/rubyonic/overview.html" 
    }) 

    .state('app.claim-details', { 
    url: "/claim-details", 
    views: { 
     'menuContent': { 
     templateUrl: "templates/rubyonic/claim_details.html" 
     } 
    } 
    }) 

    .state('app.scorecards', { 
    url: "/scorecards", 
    views: { 
     'menuContent': { 
     templateUrl: "templates/rubyonic/scorecards.html" 
     } 
    } 
    }) 

    .state('app.fnol', { 
    url: "/fnol", 
    views: { 
     'menuContent': { 
     templateUrl: "templates/rubyonic/fnol.html" 
     } 
    } 
    }) 

    // if none of the above states are matched, use this as the fallback 
    $urlRouterProvider.otherwise('/overview'); 
}); 

Oto moje controller.js:

angular.module('starter.controllers', []) 

.controller('OverviewCtrl', function($scope,Surveys) { 
     $scope.surveys = Surveys.all(); 
}) 

.controller('NavigationCtrl', function($scope, $state,$ionicHistory) { 

    // Function to go states. We're using ng-click="go('app.state')" in all our anchor tags 
    $scope.go = function(path){ 
     // console.log('working. Click was Triggered'); 
     $state.go(path); 
     // console.log($ionicHistory.viewHistory()); 
    } 

    //Function to go back a step using $ionicHistory 
    $scope.goBackAStep = function(){ 
     console.log('clicked'); 
     $ionicHistory.goBack(); 
    } 

}); 

I tu jest moje services.js:

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

.factory('Surveys',function(){ 
    var surveys = [{ 
     id: 0, 
     name: 'Honda Survey Results' 
    }, 

    { 
     id: 1, 
     name: 'Toyota Survey Results' 
    }, 
    { 
     id: 2, 
     name: 'BMW Survey Results' 
    }, 
    { 
     id: 3, 
     name: 'Nissan Survey Results' 
    }, 
    { 
     id: 4, 
     name: 'Tesla Survey Results' 
    }, 
    { 
     id: 5, 
     name: 'Mazda Survey Results' 
    }, 
    { 
     id: 6, 
     name: 'Ford Survey Results' 
    }, 
    { 
     id: 7, 
     name: 'Apple Survey Results' 
    }, 
    { 
     id: 8, 
     name: 'Microsoft Survey Results' 
    }, 
    { 
     id: 9, 
     name: 'IBM Survey Results' 
    }, 
    { 
     id: 10, 
     name: 'Amazon Survey Results' 
    } 
    ]; 
    return { 
    all: function() { 
     return surveys; 
    }, 

    get: function(surveyId) { 
     // Simple index lookup 
     return surveys[surveyId]; 
    } 
}; 
}) 

Występuje błąd: [$ injector: unpr] Nieznany dostawca: SurveysProvider < - Ankiety < - PodsumowanieC błąd trl na mojej konsoli. Myślę, że prawidłowo wstrzykiwuję usługę w kontrolerze, nie widzę problemu. Każda pomoc byłaby naprawdę doceniana.

Odpowiedz

5

Nie pamiętasz, aby określić starter.services jako zależność w module starter.controllers. Jest to ważne, ponieważ wstrzykujesz Surveys w swoim kontrolerze OverviewCtrl.

Jest to jak controller.js powinna wyglądać następująco:

angular.module('starter.controllers', ['starter.services']) 

.controller('OverviewCtrl', function($scope,Surveys) { 
     $scope.surveys = Surveys.all(); 
}) 

.controller('NavigationCtrl', function($scope, $state,$ionicHistory) { 

    // Function to go states. We're using ng-click="go('app.state')" in all our anchor tags 
    $scope.go = function(path){ 
     // console.log('working. Click was Triggered'); 
     $state.go(path); 
     // console.log($ionicHistory.viewHistory()); 
    } 

    //Function to go back a step using $ionicHistory 
    $scope.goBackAStep = function(){ 
     console.log('clicked'); 
     $ionicHistory.goBack(); 
    } 

}); 
+0

Więc dodałem angular.module ('starter.controllers' [ '']) starter.services do moich controller.js i teraz uzyskać: Uncaught Błąd: [$ wtryskiwacz: modulerr] Nie udało się utworzyć wystąpienia modułu rozrusznika z powodu: Błąd: [$ injector: modulerr] Nie można utworzyć instancji modułów starter.controllers z powodu: Błąd: [$ injector: modulerr] Nie można utworzyć instancji modułu starter.services z powodu: Błąd: [$ injector: nomod] Moduł "starter.services" nie jest dostępny! \ Próbowałem też wstrzyknąć to do mojego app.js z tym samym problemem – user1585869

+0

To prawdopodobnie dlatego, że plik controller.js jest ładowany przed usługą services.js, a zatem 'starter.controller' jest trochę nieświadomy' starter.services' sice, nie został zarejestrowany jeszcze. Aby to naprawić ... upewnij się, że plik services.js jest załadowany "before" controller.js – nalinc

1

wstrzyknąć moduł serwisowy do innego modułu jako uzależnienia, w którym chcesz uzyskać do niego dostęp.

angular.module('starter.controllers', ['starter.services']) 

Używasz usług w module Contollers, więc musisz zadeklarować także zależność.

Powiązane problemy