Node.js 搜索查询4 RESTAPI
我遵循有效的教程: 我需要为我的应用程序更改一些信息,但不起作用。 以下代码: 组成部分:Node.js 搜索查询4 RESTAPI,node.js,angular,typescript,express,Node.js,Angular,Typescript,Express,我遵循有效的教程: 我需要为我的应用程序更改一些信息,但不起作用。 以下代码: 组成部分: export class SearchComponent implements OnInit { articlePosts; results: Object; searchTerm$ = new Subject<string>(); constructor( private searchService: SearchService, private auth
export class SearchComponent implements OnInit {
articlePosts;
results: Object;
searchTerm$ = new Subject<string>();
constructor(
private searchService: SearchService,
private authService: AuthService
) {
this.searchService.search(this.searchTerm$)
.subscribe(results => {
this.articlePosts = results.articles;
});
}
}
我需要查询我数据库的数据,有人可以帮我吗?请报告具体错误和您要更改的内容不提供错误,但不显示任何数据。请报告具体错误和您要更改的内容不提供错误,但不显示任何数据。
export class SearchService {
options;
domain = this.authService.domain;
queryUrl: string = '?search=';
constructor(
private authService: AuthService,
private http: Http
) { }
// Function to create headers, add token, to be used in HTTP requests
createAuthenticationHeaders() {
this.authService.loadToken(); // Get token so it can be attached to headers
// Headers configuration options
this.options = new RequestOptions({
headers: new Headers({
'Content-Type': 'application/json', // Format set to JSON
'authorization': this.authService.authToken // Attach token
})
});
}
search(terms: Observable<string>) {
return terms.debounceTime(400)
.distinctUntilChanged()
.switchMap(term => this.searchEntries(term));
}
searchEntries(term) {
return this.http.get(this.domain + 'articles/search + this.queryUrl + term').map(res => res.json());
}
}
<input
(keyup)="searchTerm$.next($event.target.value)">
<ul *ngIf="results">
<li *ngFor="let article of articles | slice:0:9">
<a href="{{ result.latest }}" target="_blank">
{{ article.nome }}
</a>
</li>
</ul>
router.get('/search', (req, res) => {
var parsedURL = url.parse(req.url, true);
res.send(JSON.stringify(parsedURL.query));
});