如何从 angular 应用程序访问超级分类帐编写器查询?
How to access hyper ledger composer queries from angular app?
我在我的 hyperledger composer 应用程序的 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"});
我认为这对你有用。
this.http.get("http://localhost:3000/api/queries/selectPersonsByHobby?targetHobby=Football")
在 angular 应用程序中,可以通过以下方式完成:
在 app.service.ts 文件中,我们定义了 getPersonByTargetHobby 函数,我们可以在其中传递 url 和目标爱好值。通过组合 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
我在我的 hyperledger composer 应用程序的 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"});
我认为这对你有用。
this.http.get("http://localhost:3000/api/queries/selectPersonsByHobby?targetHobby=Football")
在 angular 应用程序中,可以通过以下方式完成:
在 app.service.ts 文件中,我们定义了 getPersonByTargetHobby 函数,我们可以在其中传递 url 和目标爱好值。通过组合 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