角,为什么我的组件不渲染?

时间:2020-05-12 17:50:18

标签: angular angular-routing

按照在线代码完成Angular noob。我的登录页面在路径“”上呈现,但停止了,我不知道为什么。

login.component.html

<form (submit)="loginUser($event)">
    <div class="container">
    <div>
      <input type="text" autocomplete="off" placeholder="Email" id="emailAddress">
    </div>
    <div>
      <input type="password" autocomplete="off" placeholder="Password" id="password">
    </div>
    <div>
      <button type="submit" id="submit">Submit</button>
    </div>
  </div>
  </form>

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    RouterModule.forRoot([
      {path: '',
      component: LoginComponent}
    ])
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.html

<router-outlet></router-outlet>

1 个答案:

答案 0 :(得分:0)

确保index.html文件的<base href="/">中有<head>

https://angular.io/guide/router#base-href