AOT编译失败+角度2

时间:2017-06-21 06:56:17

标签: angular angular2-services angular2-directives aot

当我为angular 2 AOT编译运行以下ngc编译命令时:

"node_modules/.bin/ngc" -p tsconfig-aot.json

我收到以下错误:

Failed on type {"filePath":"C:/Users/Admin/angular/blah/src/app/planning/planning.component.ts","na
me":"PlanningComponent","members":[]} with error Error: Error encountered resolving symbol values statically. Could n
ot resolve type Window (position 38:25 in the original .ts file), resolving symbol PlanningComponent in C:/Users/Admi
n/angular/blah/src/app/planning/planning.component.ts
Error: Error encountered resolving symbol values statically. Could not resolve type Window (position 38:25 in the ori
ginal .ts file), resolving symbol PlanningComponent in C:/Users/Admin/angular/blah/src/app/planning
/planning.component.ts

我还附加了任何参考的计划组件文件。另请找到planning.component.ts文件:

import 'web-animations-js/web-animations.min';
import { UserInfo } from './../_models/UserInfo';
import { GlobalService } from './../_services/global.service';
import { mapInternalUserInfo } from './../_utils/util';
import { LoginService } from './../login/login.service';
import { animate, Component, HostListener, OnDestroy, OnInit, state, style, transition, trigger } from '@angular/core';
import { Router } from '@angular/router';
@Component({
    templateUrl: './planning.component.html',
    styleUrls: ['./planning.component.css'],
    animations: [
        trigger('slideInOut', [
            state('in', style({
                transform: 'translate(0px, 0)'
            })),
            state('out', style({
                transform: 'translate(-229px, 0)'
            })),
            transition('in => out', animate('400ms ease-in-out')),
            transition('out => in', animate('400ms ease-in-out'))
        ]),
    ]
})
export class PlanningComponent implements OnInit, OnDestroy {
    private links = [];
    private menuState: string = 'in';
    private innerWidth: number;
    private showAdminPanel: boolean = false;
    private userInfo: UserInfo;
    private routerSubs: any;
    private breadCrumbSubs: any;
    constructor(
        private globalService: GlobalService,
        private router: Router,
        private window: Window,
        private loginService: LoginService) { }

    @HostListener('window:resize', ['$event.target'])
    public onResize() {
        this.setMenuState();
    }

    public ngOnInit() {
        this.setMenuState();
        // Subscribe to Internal user observable for user id
        console.log('Load getUser @ PlanningComponent');
        this.loginService.getUser()
            .subscribe((info) => {
                this.userInfo = mapInternalUserInfo(info.map.OBJECT);
                this.showAdminPanel = this.userInfo.role === 'Admin' ? true : false;
            },
            (err) => {
                console.error('Exception in getUser @ PlanningComponent: ', err);
            });

        // Subscribe to url changes
        this.routerSubs = this.router.events
            .subscribe((routerInfo) => {
                this.globalService.setNavStates(routerInfo.url);
            });

        // Subscribe to bread crumb changes
        this.breadCrumbSubs = this.globalService.breadCrumbEmitter
            .subscribe((links) => {
                this.links = links;
            });
    }

    // Method to toggle navigation panel for mobile view
    private toggleMenu() {
        this.menuState = this.menuState === 'out' ? 'in' : 'out';
    }

    // Unsubscribing to avoid memmory leaks
    public ngOnDestroy() {
        this.routerSubs.unsubscribe();
        this.breadCrumbSubs.unsubscribe();
    }

    // Set Navigation Panel
    private setMenuState() {
        let windowWidth = this.getWindowWidth();
        this.menuState = windowWidth < 768 ? 'out' : 'in';
    }

    // Method to get browser width
    private getWindowWidth() {
        return window.innerWidth;
    }
}

如何解决此错误?

0 个答案:

没有答案