Angular 2 typescript编译错误:没有'default'修饰符的类声明必须具有名称

时间:2016-10-24 09:29:38

标签: angular typescript

我是Angular2的新手。我的任务是将我们的项目从angular2 RC1更新为角2.1。 我将Type脚本版本从5更新为6,我看到编译问题,如:

  

没有'default'修饰符的类声明必须具有名称

与旧版本不相符。

我的ts档案:

import {
    Component,
    OnChanges,
    SimpleChange,
    OnInit,
    Input,NgModule } from '@angular/core';
import {IconComponent} from '../icon';
import { WizardPageComponent } from '../wizard';
import { StepState } from './step-state.enum';

@Component({
    selector: 'step-of-the-wizard',
    templateUrl: 'step-of-the-wizard.component.html',
    styleUrls: [ 'step-of-the-wizard.component.scss']
})

@NgModule({
    declarations:[
      IconComponent  
    ]
})




export class  implements OnChanges, OnInit {
    @Input() name:string;
    @Input() state:StepState = StepState.UNCOMPLETED;
    @Input() size:number = 30;

    @Input() vertical:boolean = false;

    public iconNameUncompleted:string = 'blank-check-box';
    public colorOfIconUncompleted:string = 'grey';
    public iconNameCompleted:string = 'check-box';
    public colorOfIconCompleted:string = 'green';
    public iconNameInActiveState:string = 'create-new-pencil-button';
    public colorOfIconInActiveState:string = 'red';
    @Input() isLast:boolean = false;
    @Input() isFirst:boolean = false;

    public associatedPage:WizardPageComponent;

    activeIcon:string = this.iconNameUncompleted
    activeColor:string = this.colorOfIconUncompleted;

    linkColor:string = this.colorOfIconUncompleted;

    ngOnChanges(changes){
        if(changes.state instanceof SimpleChange){
            switch(changes.state.currentValue){
                case StepState.COMPLETED:
                    this.activeIcon = this.iconNameCompleted;
                    this.activeColor = this.colorOfIconCompleted;
                    this.linkColor = this.colorOfIconCompleted;
                    break;
                case StepState.UNCOMPLETED:
                    this.activeIcon = this.iconNameUncompleted;
                    this.activeColor = this.colorOfIconUncompleted;
                    this.linkColor = this.colorOfIconUncompleted;
                    break;
                case StepState.ACTIVE:
                    this.activeIcon = this.iconNameInActiveState;
                    this.activeColor = this.colorOfIconInActiveState;
                    this.linkColor = this.colorOfIconUncompleted;
                    break;
                default:
                    this.activeIcon = this.iconNameUncompleted;
                    this.activeColor = this.colorOfIconUncompleted;
                    break;
            }
        }
    }
    ngOnInit() {
        if(window.matchMedia("(max-width:1000px)").matches){
            this.size = 15;
        }
    }
}

我在“@Component”声明中遇到编译错误

我尝试在谷歌搜索它但没有得到太多帮助。

我的 tsconfig 文件:

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  }

}

感谢。

1 个答案:

答案 0 :(得分:2)

你必须为你的班级命名......

替换:

export class  implements OnChanges, OnInit {

通过

export class  MyClass implements OnChanges, OnInit {