错误:$ injector:unpr未知提供者:$ localStorageProviderProvider< - $ localStorageProvider

时间:2016-10-16 16:48:09

标签: javascript angularjs typescript ng-storage

我正在尝试使用ngStorage在我的localStorage中存储一些数据。但我得到以下错误,这对我来说很奇怪:

  

错误:$ injector:unpr未知提供商未知提供商:   $ localStorageProviderProvider< - $ localStorageProvider

     

https://docs.angularjs.org/error/ $注射器/ unpr?P0 = $ localStorageProviderProvider%20%3 C-%20 $ localStorageProvider

我也在使用打字稿。这是我的代码:

app.module.ts:

(() => {

    angular.module(App.Config.MODULE_NAME, [
        'ngRoute',
        'ui.bootstrap',
        'ngStorage',
        'toastr',
    ]);

})();

register.controller.ts:

namespace App.Components.Register {
"use strict";
import IUser = App.Interfaces.IUser;
import UserDataService = App.Services.Http.UserDataService;
import IStorageProvider = angular.storage.IStorageProvider;
import ILocationService = angular.ILocationService;
import LogService = App.Services.Util.LogService;

export class RegisterController extends BaseController {

    public user: IUser;

    public static $inject: string[] = ['$localStorageProvider', '$location', 'LogService', 'UserDataService'];

    constructor(private $localStorageProvider: IStorageProvider,
                private $location: ILocationService,
                private logService: LogService,
                private UserDataService: UserDataService) {
        super();
    }

    public submit() {
        this.UserDataService.create(this.user).then(
            (data) => {
                switch (data.status) {
                    case 1:
                        this.logService.success("Usuário criado com sucesso.");
                        this.$localStorageProvider.set("user", this.user);
                        this.$location.path("/");
                        break;
                    case -1:
                        this.logService.error("Erro na criação do usuário.");
                        this.user.password = null;
                        break;
                    case -2:
                        this.logService.warning("Nome de usuário já está sendo utilizado.");
                        this.user.username = null;
                        this.user.password = null;
                        break;
                    case -3:
                        this.logService.warning("Este e-mail já está sendo utilizado.");
                        this.user.email = null;
                        this.user.password = null;
                        break;
                }
            },
            (error) => {
                this.logService.error(error);
                this.user.password = null;
            }
        );
    }
}

angular.module(App.Config.MODULE_NAME).controller('RegisterController', RegisterController);
}

对我来说奇怪的是,如果我使用$localStorage代替$localStorageProvider,它不会引发任何错误,但我不会拥有提供商的get()/set()功能。

对我来说第二件事是由angular:

生成的错误消息
  

未知提供商:$ localStorageProviderProvider< -   $ localStorageProvider

$localStorageProviderProvider上的第二个提供商来自哪里?

我知道我有解决方法,但这个错误只是进入了我的脑海,在发现问题之前我不能放手。

提前致谢。

0 个答案:

没有答案