gpt4 book ai didi

javascript - Controller 的未知提供程序错误

转载 作者:数据小太阳 更新时间:2023-10-29 06:11:01 25 4
gpt4 key购买 nike

这是我的 app.js 文件的样子:

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

这是我的 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();
}

});

这是我的 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];
}
};
})

我在控制台上收到错误:[$injector:unpr] Unknown provider: SurveysProvider <- Surveys <- OverviewCtrl 错误。我想我在 Controller 中正确注入(inject)了服务,但看不出问题所在。任何帮助将不胜感激

最佳答案

您忘记将 starter.services 指定为模块 starter.controllers 中的依赖项。这很重要,因为您要在 OverviewCtrl Controller 中注入(inject) Surveys

你的 controller.js 应该是这样的:

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

});

关于javascript - Controller 的未知提供程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31238437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com