我在Hyperledger作曲器应用程序的query.qry文件中定义了一个查询:
query selectPersonsByHobby {
description: "Select all persons with a certain hobby."
statement:
SELECT org.comp.myapp.Person
WHERE (passTime CONTAINS (name == _$targetHobby ))
}
这是模型文件的相关部分:
participant Person identified by id {
o String id
o String firstName
o String lastName
o String email
o Interest[] passTime
}
concept Interest {
o String name
o String description
}
如何从我的angular应用程序中访问查询并传递参数;
以下正确吗?
return this.httpClient.get(`http://localhost:3000/api/queries/selectPersonsByHobby`, {_$targetHobby: "Football"});
答案 0 :(得分:3)
我认为这对您有用。
this.http.get("http://localhost:3000/api/queries/selectPersonsByHobby?targetHobby=Football")
答案 1 :(得分:1)
在有角度的应用程序中,可以通过以下方式完成:
在app.service.ts文件中,我们定义了getPersonByTargetHobby函数,可以在其中传递url和目标hobby值。通过结合url + targethobby,我们将获得查询url。
/*app.service.ts File*/
import {Injectable} from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import {Observable} from 'rxjs/Observable';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable()
export class AppService {
constructor(private http:HttpClient) {}
getPersonByTargetHobby(url, tagetHobby) {
let queryUrl = url + tagetHobbys;
return this.http.get(queryUrl);
}
}
上述功能{getPersonByTargetHobby},我们可以通过这种方式在我们的组件中访问
/* First we need to import the app service in our component file {app.component.ts}*/
import { AppService } from '../app.service'
export class ComponentName implements OnInit {
constructor(private _appService: AppService){}
ngOnInit() {
url = "http://localhost:3000/api/queries/selectPersonsByHobby?targetHobby="
tagetHobby = "Football"
this._appService.getPersonByTargetHobby(url, tagetHobby).subscribe(
data => {
console.log("query response", data);
},
err => console.error(err),
() => {}
);
}
我已经对其进行了测试,希望它也适用于您。
使用HttpClient服务进行API调用: https://www.metaltoad.com/blog/angular-5-making-api-calls-httpclient-service