javascript - Angular forEach not working -


i have problem read data in angularjs.

this example fixed obj work fine:

var obj = { "done": "1"};   angular.foreach(st, function (value, key) {   alert(key + ': ' + value);   var returnval = value; //get number 1 ok }); 

my example:

http://prntscr.com/9vegm8

my function data return string ({ "done": "1"}); after replace var obj2 = data.replace("(", "").replace(")", "");get format obj in above example. obj = { "done": "1"}; obj2 = { "done": "1"};

when put obj2 in angular.foreach not working.

i'm trying use stringify,angular.fromjson nothing!

any solution?

in screenshot, obj2 json string , need parse object before sending foreach.

here working example.

var data = '({ "done": "1"});';    var obj2 = data.replace(/[();]/g, '');    angular.foreach(json.parse(obj2), function (value, key) {    alert(key + ': ' + value);    var returnval = value; //get number 1 ok  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -