美文网首页
angular 提示MainComponent is not d

angular 提示MainComponent is not d

作者: feng_wy | 来源:发表于2021-02-24 14:01 被阅读0次
    import {Component} from '@angular/core';
    
    @Component({
      selector: 'app-main-page',
      templateUrl: './main.component.html',
      styleUrls: ['./main.component.css']
    })
    export class MainComponent {
    }
    

    export class MainComponent {
    }
    这里提示红色,提示没有任何一个moudle里面定义使用。解决在app.moudle.ts定义即可

    import {NgModule} from '@angular/core';
    import {BrowserModule} from '@angular/platform-browser';
    import {RouterModule} from '@angular/router';
    import {NzButtonModule} from 'ng-zorro-antd/button';
    import {AppComponent} from './app.component';
    import {LoginComponent} from './login/login.component';
    import {NZ_I18N} from 'ng-zorro-antd/i18n';
    import {zh_CN} from 'ng-zorro-antd/i18n';
    import {registerLocaleData} from '@angular/common';
    import zh from '@angular/common/locales/zh';
    import {FormsModule} from '@angular/forms';
    import {HttpClientModule} from '@angular/common/http';
    import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
    import {MainComponent} from './main/main.component';
    
    registerLocaleData(zh);
    
    @NgModule({
      declarations: [
        AppComponent,
        LoginComponent,
        MainComponent
      ],
      imports: [
        BrowserModule,
        FormsModule,
        HttpClientModule,
        BrowserAnimationsModule,
        NzButtonModule,
        RouterModule.forRoot([
          {path: 'login-component', component: LoginComponent},
          {path: 'app', component: AppComponent}
        ])
      ],
      providers: [{provide: NZ_I18N, useValue: zh_CN}],
      bootstrap: [AppComponent]
    })
    export class AppModule {
    }
    
    

    主要是下面两句

    import {MainComponent} from './main/main.component';
    declarations: [
        AppComponent,
        LoginComponent,
        MainComponent
      ],
    

    相关文章

      网友评论

          本文标题:angular 提示MainComponent is not d

          本文链接:https://www.haomeiwen.com/subject/jylsfltx.html