Angular 7.x query to node express server is converted to an object array of characters

若如初见. 提交于 2020-01-16 14:18:12

问题


I am sending a query string to a node express server. When I access the req.query property it is an array of characters instead of a normal object or the string I sent. Any Ideas?

Query sent

const data = await this.cspCrudService.findOne(stringQuery);

service

findAll(params: any): Promise<T[]> {
 THIS LINE BELOW WAS THE PROBLEM
 const query = StringUtil.toMongoQueryString(params);
 return this.httpClient.get<T[]>(`${this.url}${this.endpoint}/${query}`).toPromise();
}

"location[$regex]=^F&location[$options]=i"

req.query

{"0":"l","1":"o","2":"c","3":"a","4":"t","5":"i","6":"o","7":"n","8":"[","9":"$","10":"r","11":"e","12":"g","13":"e","14":"x","15":"]","16":"=","17":"^","18":"F","19":"","20":"l","21":"o","22":"c","23":"a","24":"t","25":"i","26":"o","27":"n","28":"[","29":"$","30":"o","31":"p","32":"t","33":"i","34":"o","35":"n","36":"s","37":"]","38":"=","39":"i"}

回答1:


I added a "StringUtil.toMongoQueryString" function some time ago for testing and forgot it was there. After removing it all worked as expected.



来源:https://stackoverflow.com/questions/59218564/angular-7-x-query-to-node-express-server-is-converted-to-an-object-array-of-char

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!