File 'app/hero.ts' is not a module error in the console, where to store interfaces files in directory structure with angular2?

后端 未结 24 1962
无人共我
无人共我 2020-12-13 07:55

I am doing the angular2 tutorial at this address: https://angular.io/docs/ts/latest/tutorial/toh-pt3.html I have put the hero interface in a single

24条回答
  •  失恋的感觉
    2020-12-13 08:25

    The tutorial has you putting all components and the interface file in the same directory hence the relative import './hero' if you want to move it elsewhere you need to change this.

    Edit: The code may still work but the compiler will complain because you are attempting an import from an incorrect location. I'd simply change the import based on your structure. For example:

    app/
      component1/
        component1.ts
      compnent2/
        component2.ts
      hero.ts
    

    I would simply change the import to import {Hero} from '../hero'.

提交回复
热议问题