代码之家  ›  专栏  ›  技术社区  ›  Jim

尝试将窗口注入IE11上的组件时出现角度6错误

  •  0
  • Jim  · 技术社区  · 8 年前

    IE中出现以下错误:

    SCRIPT5022:无法解析StorageService:([object],?)的所有参数。

    window
    angular应用程序声明StorageService如下:

    @Injectable()
    export class StorageService implements IStorageService {
    
        /**
         * @constructor create new storage service.
         * @param window the window.
         */
        constructor(
            private readonly logger: NGXLogger,
            private readonly window: Window) {
        }
    
        /**
         * clear the token with the supplied key.
         * @param key a string containing the key.
         */
        clear(token: string) {
            window.localStorage.removeItem("token");
        }
    
        /**
         * load a value using the supplied key.
         * @param key a string
         * @returns {T} the stored value, or null;
         */
        load<T>(key: string): T {
            try {
                const value = window.localStorage.getItem(key);
                if (value === undefined || value === null || value === "undefined")
                    return null;
    
                const instance = JSON.parse(value);
                return instance as T;
            } catch (exception) {
                this.logger.warn(`error obtaining key [${key}] :: ${exception}`);
                return null;
            }
        }
    
        /**
         * save the supplied value under the supplied key.
         * @param key the key.
         * @param value the value.
         * @returns {T} the supplied value
         */
        save<T>(key: string, value: T): T {
            window.localStorage.setItem(key, JSON.stringify(value));
            return value;
        }
    }
    
    0 回复  |  直到 8 年前
    推荐文章