从客户端传递到nodeJS时,字符串变为Object

Jed*_*edi 5 javascript node.js angularjs typescript

我正在使用yeoman angular-fullstack来生成我的项目.所以客户端是angularJs(typeScript),后端是nodeJs.问题是我得到了一个变量,当我将它打印到控制台时,我得到一个非常长的字符串,(如果你需要知道它来自googleplacesapi的photo_reference).当我将它传递给带有http.get的nodeJS api,并将其打印到日志中时,我得到响应Object对象.

MainController

    for (var photo of response.data.result.photos) {
      this.getImages(photo);
      console.log(photo.photo_reference);
    }
  getImages(photo_reference: string): void{
    this.$http.get('/api/image/' + photo_reference).then((response) => {

    });
  }
Run Code Online (Sandbox Code Playgroud)

的NodeJS

export function show(req, res) {

    console.log("photoreference:" + req.params.photoreference);
Run Code Online (Sandbox Code Playgroud)

elt*_*ami 3

您向函数传递了错误的值getImages。由于传递给的参数getImages具有 photo_reference 属性,因此它是一个对象,因此日志记录是正确的

将 传递photo.photo_reference给函数

for (var photo of response.data.result.photos) {
    this.getImages(photo.photo_reference);
}
Run Code Online (Sandbox Code Playgroud)