last day (14 days later) » 

3:45 AM
0
A: show and hide in angularjs

ShomzWell, if your response comes as an empty object, then if(data !=null || data != 'undefined') won't work - it will always be true. In fact, that condition will ALWAYS be true, because no object can be a null and 'undefined' at the same time. Your Angular part seems fine, but you need to fix your...

 
what is the way to check for the empty object in angular? I tried different things but no luck so far. thanks
 
Nothing related to angular here, it's a plain js issue: stackoverflow.com/questions/4994201/is-object-empty?lq=1
The easist way would be to return false, or to check against something you know it's there after a successful call. Say, you know you'll have data.json in a successful call, then you simply check for it: if (data.json) {...
 
i am confused now :( . Please see my update 1.
 
There's no point in checking for null unless you're really returning null from the service when there's no data. If you really don't want to modify your service, use one of the functions from the link I gave you to check for an empty object.
 
i have to check for null to hide the div.
 
3:45 AM
Not for null unless your service returns null.
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop))
return false;
}

return true;
}
then simply do this in your conditional:
 
this is my shopping cart, so if cart is empty i want to say "cart is empty"
 
if (!isEmpty(data)) {... //
I understand
the whole thing
but you need to understand what I'm telling you
 
ya you right
 
checking for empty objects is a bit more complicated
and the simplest way to make it work is to return false from the service if there is no data
or, give me an example of how data looks like when there is something inside
can you paste here what data looks like when there is 1 or 2 items in the cart?
 
Object {carts: Array[1]}carts: Array[1]0: Object$$hashKey: "02S"code: "ST BUSINESS CARD 2014"description: "Business Cards 2014 Box 250"id: 1630
 
3:50 AM
perfect
if (data.carts) {...
and you're done
or if you plan to send an empty carts array at some point:
if (data.carts.length > 0) {...
 
you are genius. Need to learn how to read json format
fixed it thanks a ton
 
no problem, good luck with it :)
bye
 
bye thanks again :)
 

last day (14 days later) »