Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误:未捕获(承诺中):错误:无法匹配任何路由。URL段:';员工';E_Javascript_Angular7 - Fatal编程技术网

Javascript 错误:未捕获(承诺中):错误:无法匹配任何路由。URL段:';员工';E

Javascript 错误:未捕获(承诺中):错误:无法匹配任何路由。URL段:';员工';E,javascript,angular7,Javascript,Angular7,我正在研究Angular 7,并得到以下误差 错误 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'employees' Error: Cannot match any routes. URL Segment: 'employees' at ApplyRedirects.noMatchError (router.js:3410) at CatchSubscriber

我正在研究Angular 7,并得到以下误差

错误

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'employees'
Error: Cannot match any routes. URL Segment: 'employees'
    at ApplyRedirects.noMatchError (router.js:3410)
    at CatchSubscriber.selector (router.js:3374)
    at CatchSubscriber.error (catchError.js:29)
    at MapSubscriber._error (Subscriber.js:75)
    at MapSubscriber.error (Subscriber.js:55)
    at MapSubscriber._error (Subscriber.js:75)
    at MapSubscriber.error (Subscriber.js:55)
    at MapSubscriber._error (Subscriber.js:75)
    at MapSubscriber.error (Subscriber.js:55)
    at TapSubscriber._error (tap.js:56)
    at resolvePromise (zone-evergreen.js:797)
    at resolvePromise (zone-evergreen.js:754)
    at zone-evergreen.js:858
    at ZoneDelegate.invokeTask (zone-evergreen.js:391)
    at Object.onInvokeTask (core.js:30873)
    at ZoneDelegate.invokeTask (zone-evergreen.js:390)
    at Zone.runTask (zone-evergreen.js:168)
    at drainMicroTaskQueue (zone-evergreen.js:559)
应用程序模块.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { EmployeeComponent } from './employee/employee.component';
import { HttpClientModule } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
  declarations: [
    AppComponent,
    EmployeeComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    AppRoutingModule,
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

export class Employee {
    constructor(
        public empId: string,
        public name: string,
        public designation: string,
        public salary: string,
    ) { }
}

@Injectable({
    providedIn: 'root'
})
export class HttpClientService {

    constructor(private httpClient: HttpClient) {   }

    getEmployees() {
        console.log('Test Calls');
        return this.httpClient.get<Employee[]>('http://localhost:8080/employees');
    }
}
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { EmployeeComponent } from './employee/employee.component';

const routes: Routes = [
    { path: '', component: EmployeeComponent }
];

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

import { Component, OnInit } from '@angular/core';
import { Employee, HttpClientService } from './service/http-client.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  employees: Employee[];

  constructor(private httpClientService: HttpClientService) { }

  ngOnInit() {
    this.httpClientService.getEmployees().subscribe(
      respose => {
        this.employees = respose;
      }
    );
  }
}
http client.service.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { EmployeeComponent } from './employee/employee.component';
import { HttpClientModule } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
  declarations: [
    AppComponent,
    EmployeeComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    AppRoutingModule,
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

export class Employee {
    constructor(
        public empId: string,
        public name: string,
        public designation: string,
        public salary: string,
    ) { }
}

@Injectable({
    providedIn: 'root'
})
export class HttpClientService {

    constructor(private httpClient: HttpClient) {   }

    getEmployees() {
        console.log('Test Calls');
        return this.httpClient.get<Employee[]>('http://localhost:8080/employees');
    }
}
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { EmployeeComponent } from './employee/employee.component';

const routes: Routes = [
    { path: '', component: EmployeeComponent }
];

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

<div class="col-md-6">
  <table class="table table-striped">
    <thead>
      <tr>
        <th>Name</th>
        <th>designation</th>
      </tr>
    </thead>

    <tbody>
      <tr *ngFor="let employee of employees">
        <td>{{ employee.name }}</td>
        <td>{{ employee.designation }}</td>
        <tr>
      </tr>
    </tbody>
  </table>
</div>

名称
任命
{{employee.name}
{{employee.designation}}

您没有员工路线,只需在路线模块中为员工添加路线即可

const routes: Routes = [
    { path: '', component: EmployeeComponent },
    { path: 'employees', component: EmployeeComponent }
];

您的angular应用程序在哪个端口运行?当出现错误时?可以看到主页或浏览器中的任何页面?