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:
my function data return string ({ "done": "1"});
after replace var obj2 = data.repl
ace("(", "").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
Post a Comment