AngularJS how to alert the value of an object

I want to alert the value object

in AngularJs, how to do this?

If I just notify the object about it alert(obj)

, it shows the result as object object

in the alert box.

+3


source to share


3 answers


One of the methods -



alert(JSON.stringify(obj));

...

+6


source


If you are doing this for development purposes, just to see the contents of an object, it is much better to use the inspector in Chrome or Firebug in Firefox.

You can use a service for this $log

.



$log.info(obj);

      

This gives you the advantage that you can now see the object as a tree and you can move around. In an alert, some objects may be larger than the alert box.

0


source


It is possible to register it on the console (in any browser F12

) like

 console.log(obj);

      

or json-ify in popup alert

like

alert(angular.toJson(obj));

      

0


source







All Articles