如何确定已经加载了哪个区域? [英] How do I determine what zone is already loaded?

查看:58
本文介绍了如何确定已经加载了哪个区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有角度的最终应用程序,可以加载许多路线和模块.我开始在控制台中收到区域已加载"错误,现在又得到了两次.

I have an angular final app that loads lots of routes and modules. I started getting a "Zone is already loaded" error in the console and now I'm getting it twice.

我已经查看了区域对象以尝试弄清楚发生了什么,但是在不知道应该做什么区域的情况下几乎不可能解密.

I've looked at the zone object to try and figure out what is going on, but that is almost impossible to decipher without knowing what zone is supposed to do.

Main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';

import { environment } from './app/';
import {AppModule} from './app/app.module';

enableProdMode();

platformBrowserDynamic().bootstrapModule(AppModule,[]);

app.module.ts(我省略了所有导入):

app.module.ts (I omitted all of the imports):

@NgModule({

    imports: [ BrowserModule, RouterModule.forRoot(appRoutes), SharedModule.forRoot(), 
               HomeModule, DocumentsModule, AboutModule, SettingsModule, FoodModule, CalculatorModule, 
               ThemesModule ],
    declarations: [ AppComponent ],
    bootstrap: [ AppComponent ],
    providers: [ appRoutingProviders ]

}) 

export class AppModule {} 

app.component.ts

app.component.ts

@Component({
    moduleId: module.id,
    selector: 'kg-root',
    templateUrl: 'app.component.html',
    styleUrls: ['app.component.css']

})

export class AppComponent implements OnInit {
    private items: MenuItem[];
    appPageHeaderDivStyle: {};
    selectedTheme: Theme;
    errorMessage: string;
    loggedIn: LoggedIn;
    loggedInEmail: string = "";
    isLoggedIn: boolean;

    constructor(
        private as: AppMenuService,
        private ts: ThemeService,
        private ss: SettingsService,
        private ls: LoginService) {
    }

    ngOnInit() {

        this.ts.getNewTheme()
            .subscribe(
            theme => this.selectedTheme = theme,
            error => {
                this.errorMessage = error
            },
            () => this.completeGetNewTheme()
            );

        this.ts.setTheme("Pepper-Grinder");
        this.items = this.as.getNoLoginMenu();

        this.ls.getLoggedIn()
            .subscribe(
            loggedIn => {
                if (loggedIn.error != undefined && loggedIn.error === "" && loggedIn.email != "") {
                    this.items = this.as.getLoggedInMenu();

                    var us = this.ss.getUserSettings();
                    if (us != undefined && us.theme != null && us.theme != "") {
                        this.ts.setTheme(us.theme);
                    }
                }
                else {
                    this.items = this.as.getNoLoginMenu();
                    this.ts.setTheme("Pepper-Grinder");
                }

                this.completeLoggedIn(loggedIn.email);
            });
    }

    completeLoggedIn(email: string) {
        this.loggedInEmail = email;
        this.isLoggedIn = (this.loggedInEmail.length > 0);

    }

    completeGetNewTheme() {
        this.appPageHeaderDivStyle = this.ts.getAppPageHeaderDivStyle();
    }

推荐答案

我认为此错误意味着某些给定区域已经加载.看来这意味着"zone.js"已经加载.当我切换到Angular-cli时,它已经加载在angular-cli-build.js中.因此,将其从index.html中删除即可解决该问题.

I assumed that this error meant that some given zone was already loaded. It appears that this means that "zone.js" had already been loaded. When I switched to Angular-cli, its already loaded in the angular-cli-build.js. So removing it from the index.html solved the problem.

我正在发布此消息,以防其他人遇到该错误.

I'm posting this in case anyone else runs across the error.

这篇关于如何确定已经加载了哪个区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆