本文介绍了显示员工列表b时,函数getemployeelist会生成错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题
生成服务getallemployee时出错
problem
get error when make service getallemployee
Conversion of type 'Promise<any>' to type 'Employee[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.ts(2352)
Conversion of type 'Promise<any>' to type 'Employee[]' may be a mistake because neither type sufficiently overlaps with the other. If th
在getemployeelist函数上完成错误
如何解决这个问题呢?
我尝试过:
error done on getemployeelist function
how to solve this problem please?
What I have tried:
export class Employee {
EmployeeId : number;
BranchCode:number;
EmployeeName:string;
EmployeeAge:number;
JoinDate:Date;
BirthDate:Date;
Active : boolean;
}
import { Injectable } from '@angular/core'
import { HttpClient } from '@angular/common/http'
import {Employee} from'./employee.model'
import { Observable } from 'rxjs'
import 'rxjs/add/operator/map'
import 'rxjs/add/operator/toPromise'
import 'rxjs/add/observable/fromPromise'
import { map } from 'rxjs/operators'
@Injectable()
export class ApiService{
employeeList : Employee[];
constructor(private http : HttpClient){}
getEmployeeList(): Observable<Employee[]> {
return this.http
.get('https://localhost:44326/api/Employee')
.map((response: Response) => {
return <Employee[]>response.json();
})
.catch(this.handleError);
}
}
推荐答案
this.http
.get('https://localhost:44326/api/Employee')
.then(res => //your logic)
这篇关于显示员工列表b时,函数getemployeelist会生成错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!