使用除AppComponent之外的其他组件启动Application时遇到的问题

时间:2019-01-03 13:14:25

标签: angular angular-ui-router angular5 angular6

我正在Angular项目中工作,我不想用AppComponent启动我的应用程序,我想用FleshScreenComponent启动应用程序

为此,我已在module.ts文件的引导程序中用FleshScreenComponent替换了appComponent 但仍然出现错误->>

  

选择器“ app-flesh-screen”与任何元素都不匹配

app.module.ts

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';

    import { AppRoutingModule } from './app-routing.module';
    import { AppComponent } from './app.component';
    import { ComponentsComponent } from './components/components.component';
    import { ReactiveFormsModule } from '@angular/forms';
    import { HttpClientModule }    from '@angular/common/http';


    import { MDBBootstrapModule, WavesModule, ButtonsModule, CardsFreeModule } from 'angular-bootstrap-md';
    import { MatTabsModule, MatDialogModule } from '@angular/material';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { MatFormFieldModule} from '@angular/material';


    /*angular material compoment*/
    import { MatInputModule } from '@angular/material/input';
    import {MatButtonModule} from '@angular/material/button';
    import { RouterModule, Routes } from '@angular/router';
    import {MatSlideToggleModule} from '@angular/material/slide-toggle';
    import {MatTableModule} from '@angular/material/table';
    import {MatSelectModule} from '@angular/material/select';
    import {MatExpansionModule} from '@angular/material/expansion';
    import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
    import {MatSnackBarModule} from '@angular/material/snack-bar';
    import {MatSliderModule} from '@angular/material/slider';
    import {MatBadgeModule} from '@angular/material/badge';
    import {MatCheckboxModule} from '@angular/material/checkbox';

    /*firebase*/
    import { AngularFireModule } from 'angularfire2';
    import { AngularFirestore } from 'angularfire2/firestore';
    import { AngularFireDatabaseModule } from 'angularfire2/database';
    import {  AngularFireAuthModule} from 'angularfire2/auth';

    /*component */
    import { LoginComponent } from './login/login.component';
    import { RegisterComponent } from './register/register.component';
    import { FleshScreenComponent } from './flesh-screen/flesh-screen.component';

    // environment
    import { environment } from '../environments/environment';


    /* Service */
    import { ServicesService } from './service/services.service';
    import { ErrorComponent } from './error/error.component';
    import { MatchcenterComponent } from './matchcenter/matchcenter.component';

    @NgModule({
      declarations: [
        AppComponent,
        ComponentsComponent,
        LoginComponent,
        RegisterComponent,
        FleshScreenComponent,
        ErrorComponent,
        MatchcenterComponent
      ],
      imports: [
        BrowserModule,
        AppRoutingModule,
        BrowserAnimationsModule,
        MatInputModule,
        MatButtonModule,
        MDBBootstrapModule.forRoot(),
        ReactiveFormsModule ,
        HttpClientModule ,
        MatFormFieldModule,
        MatCheckboxModule,
        AngularFireModule.initializeApp(environment.firebase),
        AngularFireDatabaseModule,
        AngularFireAuthModule

      ],
      schemas: [ NO_ERRORS_SCHEMA ],
      providers: [ServicesService],
      bootstrap: [FleshScreenComponent]
    })
    export class AppModule { }

**routing.module.ts**

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LoginComponent } from './login/login.component';
import { RegisterComponent } from './register/register.component';
import { ErrorComponent } from './error/error.component';
import { MatchcenterComponent } from './matchcenter/matchcenter.component';





const routes: Routes = [
 { path: 'login' , component:LoginComponent },
 { path: 'register' , component: RegisterComponent },
 { path: 'error' , component: ErrorComponent},
 { path: 'matchcenter' , component: MatchcenterComponent}
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

1 个答案:

答案 0 :(得分:1)

您还需要在index.html中将<app-root></app-root>更改为<app-flesh-screen></app-flesh-screen>