If '' is an Angular component, then verify that it is part of this module

前端 未结 16 3607
慢半拍i
慢半拍i 2020-12-07 14:09

I am new in Angular2. I have tried to create a component but showing an error.

This is the app.component.ts file.

import { Component } f         


        
相关标签:
16条回答
  • 2020-12-07 14:42

    Maybe This is for name of html tag component

    You use in html something like this <mycomponent></mycomponent>

    You must use this <app-mycomponent></app-mycomponent>

    0 讨论(0)
  • 2020-12-07 14:45

    In your components.module.ts you should import IonicModule like this:

    import { IonicModule } from '@ionic/angular';

    Then import IonicModule like this:

      imports: [
        CommonModule,
        IonicModule
      ],
    

    so your components.module.ts will be like this:

    import { CommonModule } from '@angular/common';
    import {PostComponent} from './post/post.component'
    import { IonicModule } from '@ionic/angular';
    
    @NgModule({
      declarations: [PostComponent],
      imports: [
        CommonModule,
        IonicModule
      ],
      exports: [PostComponent]
    })
    export class ComponentsModule { }```
    
    0 讨论(0)
  • 2020-12-07 14:49

    Go to the tsconfig.json file. write this code under angularCompilerOption:

     "angularCompilerOptions": {
         "fullTemplateTypeCheck": true,
         "strictInjectionParameters": true,
         **"enableIvy": false**
     }
    
    0 讨论(0)
  • 2020-12-07 14:49

    I am using Angular v11 and was facing this error while trying to lazy load a component (await import('./my-component.component')) and even if import and export were correctly set.

    I finally figured out that the solution was deleting the separate dedicated module's file and move the module content inside the component file itself.

    rm -r my-component.module.ts
    

    and add module inside my-component.ts (same file)

    @Component({
      selector: 'app-my-component',
      templateUrl: './my-component.page.html',
      styleUrls: ['./my-component.page.scss'],
    })
    export class MyComponent {
    }
    
    @NgModule({
      imports: [CommonModule],
      declarations: [MyComponent],
    })
    export class MyComponentModule {}
    
    0 讨论(0)
  • 2020-12-07 14:51

    Check your selector in your filename.component.ts

    Using the tag in various html files I would say

    <my-first-component></my-first-component>
    

    Should be

    <app-my-first-component></app-my-first-component>
    

    Example

    @Component({
      selector: 'app-my-first-component',
      templateUrl: './my-first-component.component.html',
      styleUrls: ['./my-first-component.component.scss']
    })
    
    0 讨论(0)
  • 2020-12-07 14:52

    You must declare your MyComponentComponent in the same module of your AppComponent.

    import { AppComponent } from '...';
    import { MyComponentComponent } from '...';
    
    @NgModule({
       declarations: [ AppComponent, MyComponentComponent ],
       bootstrap: [ AppComponent ]
    })
    export class AppModule {}
    
    0 讨论(0)
提交回复
热议问题