Angular 2 bootstrap function gives error “Argument type AppComponent is not assignable to parameter type Type”

后端 未结 9 927
长情又很酷
长情又很酷 2021-02-01 13:14

Here is my first simple Hello World angular 2 app from Angular 2 quick start guide.

import {Component} from \'angular2/core\';
import {bootstrap} fr         


        
9条回答
  •  萌比男神i
    2021-02-01 13:50

    Actually, AppComponent is expected to extend Type. So use the following:

    // app.component.ts
    import { Component, Type } from '@angular2/core';
    
    @Component({
    ...
    ...
    })
    export class AppComponent extends Type {}
    

    This will also follow the expected convention by ng2 for AppComponent (to be bootstrapped).

    I am not sure why they didn't cover it in the ng2 tutorials, probably they might be targeting to simplify the initial learning, as it runs even without the extends part.

    This works perfectly fine in WebStorm/IntelliJ.

    Edit: Alternate solution is to update to Webstorm v2016.2 (which is stable at the time of this comment).

提交回复
热议问题