AngularJS$injector:unp未知提供程序错误

AngularJS $injector:unpr Unknown Provider Error

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

我正在尝试创建一个用户配置文件页面。用户可以在其中显示和编辑其信息。

这是我的Controller.js

var userProfileControllers = angular.module("userProfileControllers", []);
userProfileControllers.controller ('userProfileCtrl', ['$scope', '$location', 'localCache', 'customersignup', function ($scope, $location, localCache, customersignup){
	var submitProfile = function() {
 //Bind Scope
 //
 var bindScope = function () {
     $scope.userProfile = customersignup.userProfile; 
 };
 var asyncBindScope = function() {
 	$scope.$evalAsync(bindScope());
 };
 bindScope ();
 
}}]);

这是我的服务.js

var userProfileServices = angular.module("userProfileServices", []);
userProfileServices.factory("customersignup", function() {
  return {
    userProfile: {fname: "kunal"},
    updateProfile: function() {
      var userProfile = this.userProfile;
 
    },
  }
   
});

在HTML中,假设是名字,我在"名字"字段的输入中包含了ng model="userProfile.fname"。现在,当我加载html页面时,我会收到以下错误:-https://docs.angularjs.org/error/$injector/unp?p0=本地缓存提供程序%20%3C-%20localCache%20%3C-%20userProfileCtrl

请查看以上链接,它来自AngularJS官方网站。

检查您是否有两个模块,一个用于service,另一个用于controller,请注意,这两个模块之间没有粘合,要实现这一点,您需要粘合这两个模件,为此,将服务模块导入控制器模块,如下所示。

var userProfileControllers = angular.module("userProfileControllers", ['userProfileServices']);

则模块CCD_ 3可以访问定义了哪个服务的模块CCD_。其他情况下,您无法访问服务模块userProfileServices

您必须在控制器userProfileServices 中添加工厂名称