Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS log JSON

Is there a way to output JSON response that is coming from the server? I am trying the following, with undesirable output:

$http({ method: 'GET', url: 'getUser' })
        .success(function (data,status) {
            $scope.user = data;
            console.log("User="+data);})
        .error(function (data,status) {
            $scope.status = status;
            if(status==403)
                $location.path( "/" );
        });

Output:

User=[object Object] 
like image 745
Amarsh Avatar asked Sep 05 '13 08:09

Amarsh


People also ask

How to write log in Angular?

log statements in your Angular application with calls to a service. Bring up an existing Angular application or create a new one. If you don't already have one, add a folder named shared under the \src\app folder. Create a new TypeScript file named log.

How to check console log in Angular?

the console. It is used to debug an Angular application, identify performance issues, and troubleshoot problems with third-party libraries or other dependencies. We can access this function by opening the developer tools on any browser and navigating to the Console tab.

What is JSON in Angular JS?

The json filter in AngularJs is used to convert a JavaScript object into a JSON. string. JavaScript object that we are using can be of any kind of JavaScript Object.

What is filter in JSON?

Definition and Usage. The json filter converts a JavaScript object into a JSON string. This filter can be useful when debugging your applications. The JavaScript object can be any kind of JavaScript object.


1 Answers

You can stringify it before printing.

console.log("User = " + JSON.stringify(data));
like image 151
adarshr Avatar answered Oct 06 '22 09:10

adarshr