Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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 无法将函数与服务正确连接_Javascript_Angular_Typescript_Api_Swagger - Fatal编程技术网

Javascript 无法将函数与服务正确连接

Javascript 无法将函数与服务正确连接,javascript,angular,typescript,api,swagger,Javascript,Angular,Typescript,Api,Swagger,我正在尝试从端点获取单个患者的个人资料,我应该在端点发送患者Id以获取详细信息 我的服务。ts: public patientCard(patientId: string) { return this._httpClient .get( this._api_url + "patient/single?patientId=" + encodeURIComponent(JSON.stringify(pat

我正在尝试从端点获取单个患者的个人资料,我应该在端点发送患者Id以获取详细信息

我的服务。ts:

public patientCard(patientId: string) {
    return this._httpClient
      .get(
        this._api_url +
          "patient/single?patientId=" +
          encodeURIComponent(JSON.stringify(patientId))
      )
      .pipe(
        map((data: APIResult<Array<PatientObject>>) => {
          console.log("Response: -->", data.result);
          return data.result;
        }),
        catchError(this._handleError)
      );
  }
my model.ts:

export class PatientObject {
  constructor(
    public patientId?: string,
    public name?: string,
    public surname?: string,
    public dob?: string | Date,
    public note?: string,
    public isFzo?: boolean,
    public gender?: string,
    public embg?: string,
    public phoneNumber?: string,
    public contactEmail?: string
  ) {}
}
以下是我迄今为止所做的工作。检查我的

我还是个新手,所以要记住这一点:D


提前感谢所有的帮助

//假设您的路线是//////////

{  path:"yourRout/:id", component:yourComponent} 
import { ActivatedRoute, Params} from '@angular/router';

patientInfo:PatientObject;
patientId:string;

  constructor(private appService:appService,
    private route:ActivatedRoute) { }
    
    

    ngOnInit(): void 
    {   //get the patientId from the route
        
         //updated this code start
         this.route.queryParams.subscribe((params)=>
         {
              this.patientId = params['patientId']; 
              this.patientCard();   
        })
          //updated this code end
    }
    
    
    patientCard() 
    {
          this.appService
          .patientCard(this.patientId)
          .subscribe((data: any) => 
          {
              //here you may get the patient info
              this.patientInfo = data;
              //this.patientId = data.patientId;
          });
    }
    
////////Component.ts文件//////////////

{  path:"yourRout/:id", component:yourComponent} 
import { ActivatedRoute, Params} from '@angular/router';

patientInfo:PatientObject;
patientId:string;

  constructor(private appService:appService,
    private route:ActivatedRoute) { }
    
    

    ngOnInit(): void 
    {   //get the patientId from the route
        
         //updated this code start
         this.route.queryParams.subscribe((params)=>
         {
              this.patientId = params['patientId']; 
              this.patientCard();   
        })
          //updated this code end
    }
    
    
    patientCard() 
    {
          this.appService
          .patientCard(this.patientId)
          .subscribe((data: any) => 
          {
              //here you may get the patient info
              this.patientInfo = data;
              //this.patientId = data.patientId;
          });
    }
    

你怎么让patientId进入ngOnInit?这就是我寻求帮助的原因。我知道我应该把病人送到那里,但不知道从哪里取。我也尝试过使用此.appservice,但没有成功。添加用于到达此组件的路由。您能否告诉我如何操作,因为我在路由中有Id,如何从那里获取并发送到函数?您的路由看起来如何显示routing.module.ts文件?这是我一直得到的。我尝试了这么多选项,但结果仍然是:500(内部服务器错误)**patient.service.ts:116后端返回代码500,body was:[object object]**您尝试过上述答案吗?在api中为“undefined”正在传递patientId,因为实际上在您的代码中,您没有正确地传递patientId。我尝试了上面的代码,但仍然得到相同的错误。即使我尝试从参数中控制台.out patientId,它也会返回一个未定义的数据。除了“this.route.params”之外,只需使用“this.route.queryParams”即可编辑代码