Why isn't “export default” recommended in Angular?

后端 未结 1 635
终归单人心
终归单人心 2021-01-04 08:18

According to the Typescript documentation (section \"Guidance for structuring modules\"):

If you’re only exporting a single class or function, use

相关标签:
1条回答
  • 2021-01-04 08:31

    The actual reason is that this doesn't work with the AOT compiler, however it will work with the JIT compiler. So if you are using AOT (or want to use it moving forward), don't do export default. See also here:

    Default Exports

    Default exports aren't allowed with AoT - they must all be named.

    ❌ DONT:

    import { Component } from '@angular/core';
    
    @Component({
      template: `
        <div class="example">
          Example component!
        </div>
      `
    })
    export default class ExampleComponent {
    
    }
    

    ✅ DO:

    import { Component } from '@angular/core';
    
    @Component({
      template: `
        <div class="example">
          Example component!
        </div>
      `
    })
    export class ExampleComponent {
    
    }
    
    0 讨论(0)
提交回复
热议问题