我有这个问题,我的应用程序工作正常,但此错误显示在 IDE 中。
员工.service.ts:
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class EmployeeService {
getEmployee(){
return [
{"id":1,"name":"Micheal","age":21},
{"id":2,"name":"Jackson","age":22},
{"id":3,"name":"Hales","age":23},
{"id":4,"name":"Moz","age":25}
];
}
constructor() { }
}
Run Code Online (Sandbox Code Playgroud)
我的employeeDetail.ts 文件是这样的:
import { Component, OnInit } from '@angular/core';
import { EmployeeService } from '../services/employee.service';
@Component({
selector: 'employee-detail',
templateUrl: './employee-detail.component.html',
styleUrls: ['./employee-detail.component.css']
})
export class EmployeeDetailComponent implements OnInit {
public employees = [];
constructor(private _employeeService : EmployeeService) {
}
ngOnInit() {
this.employees = this._employeeService.getEmployee();
}
}
Run Code Online (Sandbox Code Playgroud)
这是 Employee-list.ts
import { Component, OnInit } from '@angular/core';
import {HttpClientModule} from '@angular/common/http';
import { EmployeeService } from '../services/employee.service';
@Component({
selector: 'employee-list',
templateUrl: './employee-list.component.html',
styleUrls: ['./employee-list.component.css']
})
export class EmployeeListComponent implements OnInit {
public employees = []
constructor(private _employeeService : EmployeeService) {
}
ngOnInit() {
this.employees = this._employeeService.getEmployee();
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?实际问题是什么?因为我是 angular6 的新手,所以我无法弄清楚错误,请解释一下。谢谢你。
我没有看到您的代码有任何问题,因为我认为您应该停止应用程序Ctrl + C
然后做ng serve
无论如何,原因是,您的 getEmployee 方法仍然需要传递一个参数,只需确保您的代码保存在服务部分即可。
| 归档时间: |
|
| 查看次数: |
14126 次 |
| 最近记录: |