错误未定义,HttpErrorResponse。{标题:HttpHeaders,状态:404,statusText:“未找到”

时间:2019-12-04 04:30:20

标签: http ionic4

我有点担心,如果有人可以帮到我,我会使用laravel 5.8 API创建,当我从posteman的walk检索参数数据mtr时,但是当我使用此url执行相同的操作时,我< http://127.0.0.1:8000/api/studentbyid/45'>>可以解决它的问题,因为45是mtr,而根据我尝试设置的逻辑,则由用户介绍mtr,然后显示。 ..

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Candidate } from '../models/candidate';

@Component({
  selector: 'app-candidate',
  templateUrl: './candidate.page.html',
  styleUrls: ['./candidate.page.scss'],
})
export class CandidatePage implements OnInit {
  mtr: '45';
  // tslint:disable-next-line: new-parens
  data: any;
  url = 'http://127.0.0.1:8000/api/studentbyid/';

  constructor( private httpClient: HttpClient) { }

  ionViewWillEnter(mtr: string) {
    return this.httpClient.get(this.url + '/' + this.mtr)
      .subscribe(
        data => {
          this.data = JSON.stringify(data);
          console.log(this.data);
        }, 
        error => {
          console.log(error);
        });
   }

  ngOnInit() {}

  getbyID( mtr: string) {}

}

这是我直接放置在控制台中的结果 enter image description here 这就是我尝试从用户那里检索单词的时候enter image description here

如果有人可以帮助我,而我注意到没有对象形式的答案

2 个答案:

答案 0 :(得分:0)

您的变量mtr确实未定义。

mtr: '45';

console.log(mtr);
// undefined

您需要将变量设置为'45'字符串,而不是将mtr变量键入为'45'类型。

mtr: string = '45';

console.log(mtr);
// '45'

答案 1 :(得分:0)

Merci Tomas,sa marche lerésultatque j'attend est la,sauf une petit erreur encore, enter image description here