Angularjs 获得';错误:[$injector:unpr]未知提供程序:';错误

Angularjs 获得';错误:[$injector:unpr]未知提供程序:';错误,angularjs,Angularjs,我正在尝试创建一个动态下拉选择菜单。我得到一个未知的提供程序错误,该错误与我用来创建日期范围的函数有关。这是我的密码: HTML 工厂 var myApp = angular.module('myApp',[]); myApp.factory('catagories',function(){ var makes = {}; makes.cast = [ { value: "acura", text: "Acura" }, { v

我正在尝试创建一个动态下拉选择菜单。我得到一个未知的提供程序错误,该错误与我用来创建日期范围的函数有关。这是我的密码:

HTML

工厂

var myApp = angular.module('myApp',[]);

myApp.factory('catagories',function(){
  var makes = {};
  makes.cast = [
  {
    value: "acura",
    text: "Acura"
  },
  {
    value: "audi",
    text: "Audi"
  },
  {
    value: "geo",
    text: "Geo"
  },
  {
    value: "hummer",
    text: "Hummer"
  },
  ];
  return makes;
});

myApp.factory('acura',function( production_range,makesProductionEnded, makesInProduction){

var endedProductionObject = makesProductionEnded.filter(function( obj)               {
    return obj.make === this;
});

$scope.acura ={};
$scope.start = 1986 <!-- date Honda began production of the Acura product line -->

<!-- Set the most recent year option if still in production according to current month and model year change over October  -->
$scope.setEnd = function(){  
  if($inArray(this, makesInProduction) > 0){
    if(new Date().getMonth() < 10){
      end = new Date().getFullYear();
    } else {
      end = new Date().getFullYear() + 1;
    }

<!-- Set most recent year option if no longer in production according to year property value of object that matches this make in the endedProductionObject array  -->       
} else {
    end = endedProductionObject.year;                                                      
}
    return end;
}

$scope.acura.cast = [];
angular.foreach(years, function(value, year){
    acura.cast.push(acura[year] = value);
  });
  return acura;
});

myApp.factory('audi',function(){
  var audi = {};
  audi.cast = [
 <!--This will follow a similar pattern as acura once that is resolved -->
  ];
  return audi;
});

myApp.factory('geo',function(){
  var geo = {};
  geo.cast = [
 <!--This will follow a similar pattern as acura once that is resolved -->
  ];
  return geo;
});

myApp.factory('hummer',function(){
  var hummer = {};
  hummer.cast = [
<!--This will follow a similar pattern as acura once that is resolved -->
  ];
  return hummer;
});
var myApp=angular.module('myApp',[]);
myApp.factory('categories',function()){
var使={};
makes.cast=[
{
价值:“极品”,
文字:“Acura”
},
{
价值:“奥迪”,
文字:“奥迪”
},
{
价值:“地理”,
案文:“Geo”
},
{
价值:“悍马”,
文字:“悍马”
},
];
回报;
});
myApp.factory('acura',功能(生产范围、制造商生产、制造商生产){
var endedProductionObject=makesProductionEnded.filter(函数(obj){
返回obj.make==this;
});
$scope.acura={};
$scope.start=1986
$scope.setEnd=function(){
如果($inArray(这个,makesInProduction)>0){
如果(新日期().getMonth()<10){
结束=新日期().getFullYear();
}否则{
结束=新日期().getFullYear()+1;
}
}否则{
结束=endedProductionObject.year;
}
返回端;
}
$scope.acura.cast=[];
角度。foreach(年,函数(值,年){
acura.cast.push(acura[年份]=数值);
});
回归针;
});
myApp.factory('audi',函数(){
var={};
奥迪.卡斯特=[
];
返回奥迪;
});
myApp.factory('geo',function(){
var geo={};
geo.cast=[
];
返回geo;
});
myApp.factory('hummer',function()){
var-hummer={};
hummer.cast=[
];
返回悍马;
});
控制器

myApp.controller('makeTypeCtrl',function($scope, acura, audi, geo,hummer, setNulls, catagories, production_range){

<!-- Push the model years into the years array according to the start and end dates  -->
  $scope.production_range = function(start, end){
    var years = [];

    for(var year = start; year <= end; year++){
        years.push(year);
    }
    return years;
  }

<!-- Defines the makes no longer in production and the date production ended for that make -->
$scope.makesProductionEnded = [{make:'eagle', year:1999}, {make:'geo', year:1997}]

<!-- Defines makes still in production -->
$scope.makesInProduction = ['acura', 'audi'];

$scope.catagories = catagories;
$scope.types = setNulls;
$scope.changeData = function() {        
  if($scope.itemsuper.text == "Acura") {
        $scope.types = acura;
    } else if($scope.itemsuper.text == "Audi") {
        $scope.types = audi;
    } else if($scope.itemsuper.text == "Geo") {
        $scope.types = geo;
    } else if($scope.itemsuper.text == "Hummer") {
        $scope.types = hummer;
    } else {
        $scope.types = setNulls;
    }   
  }
});
myApp.controller('makeTypeCtrl',函数($scope、acura、audi、geo、hummer、setNulls、categories、production\u range){
$scope.production\u range=功能(开始、结束){
风险值年数=[];
对于(var年=开始;年)
$scope.makesInProduction=['acura','audi'];
$scope.catagories=类别;
$scope.types=setNulls;
$scope.changeData=function(){
如果($scope.itemsuper.text==“Acura”){
$scope.types=acura;
}else if($scope.itemsuper.text==“Audi”){
$scope.types=奥迪;
}else if($scope.itemsuper.text==“Geo”){
$scope.types=geo;
}else if($scope.itemsuper.text==“Hummer”){
$scope.types=悍马;
}否则{
$scope.types=setNulls;
}   
}
});

这里有一个到的链接。问题是您正试图将
生产范围
注入您的
acura
工厂。但是
生产范围
是控制器范围内的一个变量,而不是可以注入的工厂或服务

工厂的第二个参数应该是一个以依赖项为参数的函数。所谓依赖项,我指的是工厂/服务或从提供者创建的任何其他内容,请参阅和。
也请阅读以下内容:

就是这样。谢谢@BenWilde
myApp.controller('makeTypeCtrl',function($scope, acura, audi, geo,hummer, setNulls, catagories, production_range){

<!-- Push the model years into the years array according to the start and end dates  -->
  $scope.production_range = function(start, end){
    var years = [];

    for(var year = start; year <= end; year++){
        years.push(year);
    }
    return years;
  }

<!-- Defines the makes no longer in production and the date production ended for that make -->
$scope.makesProductionEnded = [{make:'eagle', year:1999}, {make:'geo', year:1997}]

<!-- Defines makes still in production -->
$scope.makesInProduction = ['acura', 'audi'];

$scope.catagories = catagories;
$scope.types = setNulls;
$scope.changeData = function() {        
  if($scope.itemsuper.text == "Acura") {
        $scope.types = acura;
    } else if($scope.itemsuper.text == "Audi") {
        $scope.types = audi;
    } else if($scope.itemsuper.text == "Geo") {
        $scope.types = geo;
    } else if($scope.itemsuper.text == "Hummer") {
        $scope.types = hummer;
    } else {
        $scope.types = setNulls;
    }   
  }
});