Yasir
Yasir

Reputation: 101

AngularJS how to alert object value

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.

Upvotes: 4

Views: 8377

Answers (3)

ΩmegaMan
ΩmegaMan

Reputation: 31576

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));

Upvotes: 0

Nurdin
Nurdin

Reputation: 23883

One way is

alert(JSON.stringify(obj)); .

Upvotes: 8

Sergey Romanov
Sergey Romanov

Reputation: 3080

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.

Upvotes: 0

Related Questions