AngularJS 未知提供程序

AngularJS Unknow provider

本文关键字:程序 未知 AngularJS      更新时间:2023-09-26

我试图在我的 Angular 应用程序中设置一个新的控制器,但我遇到了这个错误:

[$injector:UNPR] http://errors.angularjs.org/1.4.2/$injector/unpr?p0=successRedirectProvider%20%3C-%20successRedirect%20%3C-%20ingreCtrl。

我尝试了很多东西几个小时,但仍然有这个问题。这是我的文件:

应用.js:

var app = angular.module('app', ['formSubmit']);
app.factory('successRedirect', function(){
return function(data) {
  if(data.status === "success") {
    alert(data.message);
    if (typeof(data.redirect) !== "undefined"){
      document.location.href = data.redirect;
    }
  }else{
  }
  };
});
app.factory('errors', function(){
return function(data) {
  alert(data.message)
  for(var i = 0; i<data.errors.length;i++){
    $('#new-page-form-container').append('<p>'+data.errors[i]+'</p>');
  }
     };
});

表单应用.js:

var formSubmit = angular.module('formSubmit', ['ckeditor', 'ngFileUpload']);

成分控制.js:

  formSubmit.controller('ingreCtrl', ['$scope', '$filter', '$http',  'successRedirect', 'errors', function ($scope, $filter, $http, successRedirect,   errors) {
}]);

您正在尝试在formSubmit模块中使用app模块的successRedirect服务。这意味着您需要将依赖项注入app formSubmit

var formSubmit = angular.module('formSubmit', ['app', 'creditor', 'ngFileUpload']);
                                               ^^^^^

反之则不然。

我终于找到了它不起作用的原因,上周我在另一个文件中为我网站的登录系统做了另一个模块,我不记得我已经给这个模块起了名字"app",所以我在文件应用程序中更改了我的模块名称.js它就可以工作了。但是要回答一些评论,我的依赖注入很好,作为我的包含,不需要更改顺序。问题是模块名称。无论如何,感谢您的时间,主题关闭^^