giving $get,$update,$query when iterating JSON object at client side;.

24 views
Skip to first unread message

Deeksha Sharma

unread,
Mar 27, 2014, 6:50:46 AM3/27/14
to ang...@googlegroups.com
 Hey all,
I am calling a web api from angularjs and iterating the JSON object but at the time of iteration .It is giving some unexpected  terms like $get,$update,$remove etc.
How can I resolve this problem.


$scope.Customers=customerService.getCustomers($scope.limit, $scope.offset).$promise.then(function (data) {
alert(data);
for (var index in JSONData[0]) {
                                alert(index);
                                if (index != "AddressDetail")
                                {
                                    row += index + ',';
                                }
                                if (index == "AddressDetail") {
                                    for (var indexx in arrData[0]["AddressDetail"])
                                    {
                                        if (indexx == "addressDetailId") {
                                            continue;
                                        }
                                        row += indexx + ',';
                                    }
                                }
                                //alert(index);
                            }   

Luke Kende

unread,
Mar 28, 2014, 2:09:17 AM3/28/14
to ang...@googlegroups.com
Any time you use "for in" you will get every property including prototype methods and properties of an object (arrays are still objects).  To avoid this, use hasOwnProperty:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty

for (var item in items){
    if (items.hasOwnProperty(item) ){
        ..... your code here .....

Deeksha Sharma

unread,
Mar 28, 2014, 9:07:27 AM3/28/14
to ang...@googlegroups.com
Hey Luke Kende,
thanks for your suggestion  ,I did it by using angular.toJson.

Thank u once again.


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/nkTcNKpd9cA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Luke Kende

unread,
Mar 28, 2014, 12:57:24 PM3/28/14
to ang...@googlegroups.com
That works to... just be aware of for-in and prototype properties.  toJson uses the hasOwnProperty or similar in converting.
Reply all
Reply to author
Forward
0 new messages