Javascript 类型A缺少类型B中的以下属性:A,B
我很难修复此错误:Javascript 类型A缺少类型B中的以下属性:A,B,javascript,html,angular,typescript,Javascript,Html,Angular,Typescript,我很难修复此错误: Type 'Mahasiswa[]' is missing the following properties from type 'MahasiswaResult': info, result 我在这里试图做的是获取请求,并将数据获取到下面的HTML中。 以下是用户详细信息.component.html: <div class="container-fluid pt-3 pb-3"> <p>Current NIM: {{currentNIM}}<
Type 'Mahasiswa[]' is missing the following properties from type 'MahasiswaResult': info, result
我在这里试图做的是获取请求,并将数据获取到下面的HTML中。
以下是用户详细信息.component.html
:
<div class="container-fluid pt-3 pb-3">
<p>Current NIM: {{currentNIM}}</p>
<p>Ini Halaman Detailnya Khusus Untuk ::</p>
<p>{{ mahasiswa.result.alamat }} ~~ {{ mahasiswa.result.nama_lengkap }} -- {{ mahasiswa.result.email }}</p>
pelayan api.service.ts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { PelayanApiService } from '../_shared/services/pelayan-api.service';
import { MahasiswaResult } from '../_shared/models/mahasiswa-result';
@Component({
selector: 'app-user-detail',
templateUrl: './user-detail.component.html',
styleUrls: ['./user-detail.component.css']
})
export class UserDetailComponent implements OnInit {
public mahasiswa: MahasiswaResult;
currentNIM: string;
constructor(private pelayan: PelayanApiService,
public activatedRoute: ActivatedRoute) { }
ngOnInit() {
this.currentNIM = this.activatedRoute.snapshot.paramMap.get("nim");
this.pelayan.getMahasiswaByNim(this.currentNIM).subscribe(result => {this.mahasiswa = result; console.log(this.mahasiswa)});
}
}
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Mahasiswa } from '../models/mahasiswa';
@Injectable({
providedIn: 'root'
})
export class PelayanApiService {
private apiDocumentation = 'https://documenter.getpostman.com/view/5658787/SW7W5pjd';
private urlApi = 'https://umn-pti2019.herokuapp.com';
constructor(private http: HttpClient) { }
getAllMahasiswa(): Observable<Mahasiswa> {
return this.http.get<Mahasiswa>(`${this.urlApi}/api/mahasiswa`);
}
getMahasiswaByNim(nim: string): Observable<Mahasiswa[]> {
return this.http.get<Mahasiswa[]>(`${this.urlApi}/api/mahasiswa/${nim}`);
}
}
export interface MahasiswaResult {
info: string;
result: {
alamat: string;
angkatan: string;
created_at: string;
email: string;
foto: string;
id: string;
nama_lengkap: string;
nim: string;
prodi: string;
tanggal_lahir: string;
telepon: string;
updated_at: string;
};
}
以下是获取的API示例:
{"info":"Univ Student You are returning Mahasiswa[] from the function below in the service
getMahasiswaByNim(nim: string): Observable<Mahasiswa[]> {
return this.http.get<Mahasiswa[]>(`${this.urlApi}/api/mahasiswa/${nim}`);
}
{“info”:“Univ Student您正在从服务中的以下函数返回Mahasiswa[]
getMahasiswaByNim(nim: string): Observable<MahasiswaResult> {
return this.http.get<MahasiswaResult>(`${this.urlApi}/api/mahasiswa/${nim}`);
}
getMahasiswaByNim(nim:string):可观察{
返回this.http.get(`this.urlApi}/api/mahasiswa/${nim}`);
}
试着把它改成
getMahasiswaByNim(nim:string):可观察{
返回this.http.get(`this.urlApi}/api/mahasiswa/${nim}`);
}
您正在从服务中的以下函数返回Mahasiswa[]
getMahasiswaByNim(nim: string): Observable<MahasiswaResult> {
return this.http.get<MahasiswaResult>(`${this.urlApi}/api/mahasiswa/${nim}`);
}
getMahasiswaByNim(nim:string):可观察{
返回this.http.get(`this.urlApi}/api/mahasiswa/${nim}`);
}
试着把它改成
getMahasiswaByNim(nim:string):可观察{
返回this.http.get(`this.urlApi}/api/mahasiswa/${nim}`);
}