Skip to content

angular http response.text() now returns [object Object]. Previously [{"Id":1,"Name":"BUC ...  #89

Closed
@matt4446

Description

@matt4446

It's not a big issue, and a little awkward to ask now :) ... as I get my array of objects from .json() in my last issue.

I pretty much cleared my logging after that so I've only just noticed. Feel free to keep things the way they are as its just a nice to know.

let text = response.text();
console.log(text);

results in:

JS: =Debug===============
JS: [object Object],[object Object],[object Object]

It is a string (I checked)... just a very insignificant string.
The '.text()' version should be the result body (i imagine its due to the content type header, which was fixed in core to automatically serialize) when the command should result in the content body in text format.

Previous text:

JS: [{"Id":1,"Name":"BUCS","Logo":"content/logos/bucs-logo.jpg","CompetitionCount":4},{"Id":2,"Name":"SUTL","Logo":"content/logos/sutl.jpg","CompetitionCount":8},{"Id":1008,"Name":"South East Region","Logo":null,"CompetitionCount":4}]

The later is quite useful for debugging, but I don't really have a use case beyond that.

I have a workaround for the moment:

var subscription = requestObservable.subscribe(response => {
    let text = response.text();
    let json = response.json();

    this.Notify(text);
    let jsonAsText = JSON.stringify(json)
    this.Notify(jsonAsText);
});

Results in:

JS: =Debug===============
JS: 2016-02-25T23:27:46.876Z: [object Object],[object Object],[object Object]
JS: ======================
JS: =Debug===============
JS: 2016-02-25T23:27:46.878Z: [{"Id":1,"Name":"BUCS","Logo":"content/logos/bucs-logo.jpg","CompetitionCount":4},{"Id":2,"Name":"SUTL","Logo":"content/logos/sutl.jpg","CompetitionCount":8},{"Id":1008,"Name":"South East Region","Logo":null,"CompetitionCount":4}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions