2015-07-06 35 views
5

đây là những gì tập tin app.js của tôi trông giống như:lỗi nhà cung cấp không rõ cho điều khiển

// 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'); 
}); 

Đây là controller.js tôi:

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(); 
    } 

}); 

Và đây là services.js tôi:

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]; 
    } 
}; 
}) 

Tôi gặp lỗi: [$ injector: unh] Nhà cung cấp không xác định: SurveysProvider < - Khảo sát ý kiến ​​< - OverviewC lỗi trl trên bảng điều khiển của tôi. Tôi nghĩ rằng tôi đang tiêm dịch vụ một cách chính xác trong bộ điều khiển không thấy vấn đề là gì. Mọi trợ giúp sẽ thực sự được đánh giá cao

Trả lời

5

Bạn quên chỉ định starter.services làm phụ thuộc trong mô-đun starter.controllers. Điều này quan trọng vì bạn đang tiêm Surveys trong bộ điều khiển OverviewCtrl của mình.

Đây là cách controller.js của bạn sẽ giống như thế:

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

Vì vậy, tôi đã thêm angular.module ('starter.controllers', ['starter.services']) vào controller.js của mình và bây giờ tôi nhận được: Lỗi bắt buộc: [$ injector: modulerr] Không thể khởi tạo mô-đun khởi động do: Lỗi: [$ injector: modulerr] Không thể khởi tạo mô-đun starter.controllers do: Lỗi: [$ injector: modulerr] Không thể khởi tạo mô-đun starter.services do: Lỗi: [$ injector: nomod] Module 'starter.services' không khả dụng! \ Tôi cũng đã thử tiêm nó vào app.js của tôi với cùng một vấn đề – user1585869

+0

Thats có lẽ vì controller.js đang được nạp trước services.js và do đó 'starter.controller' là kinda không biết về' starter.services' sice nó chưa được đăng ký chưa. Để khắc phục nó..simply đảm bảo rằng services.js được tải 'before' controller.js – nalinc

1

Tiêm mô-đun dịch vụ của bạn để mô-đun khác như phụ thuộc nơi bạn muốn truy cập vào nó.

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

Bạn đang sử dụng dịch vụ trong mô-đun contollers, vì vậy bạn cũng cần khai báo sự phụ thuộc.

Các vấn đề liên quan