首页 > 解决方案 > 如何迭代从可观察的响应返回的数据

问题描述

大家好,我是 JavaScript 新手,开始学习 Angular。这是 Spring Boot 应用程序返回的应用程序的响应。我想知道如何使用 ForEach 循环来交互这个 UserCred 对象。

Response from the Server

UserCred {username: "Prawin", password: "password"}
password: "password"
username: "Prawin"
__proto__:
constructor: class UserCred
arguments: (...)
caller: (...)
length: 2
name: "UserCred"
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: user-registration.service.ts:6
[[Scopes]]: Scopes[2]
__proto__:
constructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ ()
valueOf: ƒ valueOf()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
get __proto__: ƒ __proto__()


返回响应的一段代码。


  handleLogin(){
    console.log("inside Login");
    console.log(this.username);
    console.log(this.password);
    this.userRegistartionService.postUserCredientials(this.username, this.password)
      .subscribe(data => {
        console.log(typeof data);
        this.loginService.aunthenticate(this.username);
        this.router.navigate(["application/manage"]);
      });
  }


我需要从名为“data”的响应对象中获取数据

我想具体获取用户名和密码。因为它是一个响应对象,所以我正在努力使用 ForEach 循环获取数据。

标签: angulartypescriptecmascript-6

解决方案


推荐阅读