4

I want to alert an object value in AngularJs, how does one do that?

If I simply alert the object by alert(obj) then it shows the result as object object in alert box.

1
  • 2
    Try alert(JSON.stringify(obj)); Commented Oct 2, 2014 at 7:56

3 Answers 3

8

One way is

alert(JSON.stringify(obj)); .

Sign up to request clarification or add additional context in comments.

1 Comment

In fact most correct way in Angular would be to use angular.toJson(obj)
0

If you do it for development purpose just to see object content, much better to use inspector in Chrome or Firebug in Firefox.

You can use $log service for that.

$log.info(obj);

This gives you advantage that you can now see object as tree and you can navigate. In alert some objects may be bigger that alert window.

2 Comments

i am using angularJS in phonegape, so how i see output using this?
Use Ripple chrome extension to emulate phonegap app in Chrome but like you run it on a device. And use standard chrome inspector then.
0

One can log it to the console (in any browser's F12 tools) such as

 console.log(obj);

or to json-ify it in the alert popup such as

alert(angular.toJson(obj));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.