我有一个单页应用程序,Angular(v5)用于前端,如何在我的应用程序中使用bing搜索。?
我搜索了很多,但未能找到解决方案。
在official site可用于Node.Js
我如何将其整合为角度。? 感谢。
答案 0 :(得分:0)
您将使用http
API直接使用角度应用程序中的API。
请检查here中的教程以处理角度中的https请求。
请查看以下摘要以获取帮助,
import { Headers, RequestOptions } from '@angular/http';
//your component method
doSearch() {
let subscriptionKey = 'YOUR-SUBSCRIPTION-KEY';
let customConfigId = 'YOUR-CUSTOM-CONFIG-ID';
let searchTerm = 'microsoft';
let headers = new Headers();
headers.append('Ocp-Apim-Subscription-Key', subscriptionKey);
let opts = new RequestOptions();
opts.headers = headers;
// here your url
let url = 'https://api.cognitive.microsoft.com/bingcustomsearch/v7.0/search?' +
'q=' + searchTerm +
'&customconfig=' + customConfigId,
// http rquest
this.http.get(url, opts).subscribe(
res => console.log('handle your response',res.json()),
msg => console.error(`Error: ${msg.status} ${msg.statusText}`)
);
}
不记得确切,但你可以尝试使用上面的片段。
否则,如果后端有node
,请为endpoints
创建自己的Bing Custom Search endpoint
,并使用请求处理程序在您的应用中使用它们。
希望这会对你有所帮助!!