Page 1 of 1

Hiding 'undefined' text in Ionic

Posted: Sat Jun 11, 2016 12:20 am
by Matt Simoncavage

Hi, I'm making the switch from JQuery to Ionic and completely rebuilding my app in the new framework. In JQuery, I used the following javascript to hide a database record from a list component is it was blank: element.hide(). I'm wondering if there is an equivalent to this in Ionic. I tried the same code, but it didn't work. Thanks.


Hiding 'undefined' text in Ionic

Posted: Mon Jun 13, 2016 3:48 pm
by Serhii Kulibaba

Hello Matt,

Please use ng-hide attribute of the component for that: https://docs.angularjs.org/api/ng/dir...


Hiding 'undefined' text in Ionic

Posted: Mon Jun 13, 2016 8:08 pm
by Matt Simoncavage

Hi Sergiy, thanks for the help. Is there a way to use ng-hide only for a certain value? For example, if I'm pulling data from the database to a list component, I'd like to hide any list item that equals "value".


Hiding 'undefined' text in Ionic

Posted: Tue Jun 14, 2016 3:10 pm
by Serhii Kulibaba

Yes, it is possible. You are able to use any construction there, e.g. set it's value:
prelike a condition: myVariable==3
or result of the function:
myFunction()
/pre


Hiding 'undefined' text in Ionic

Posted: Tue Jun 14, 2016 7:36 pm
by Matt Simoncavage

Thanks again Sergiy, I was making it more complicated than it was.

I used: myVariable==value

One more question: I tried to add a second ng-hide attribute but it's only letting me have one. Is there a way to use that condition for two values?

Example:
myVariable--value1,value2


Hiding 'undefined' text in Ionic

Posted: Wed Jun 15, 2016 3:51 pm
by Serhii Kulibaba

You are right, it is possible to use only one ng-hide attribute, please use boolean and/or for that, e.g.:

pre(myVariable==value ) ||( myVariable==value2) /pre


Hiding 'undefined' text in Ionic

Posted: Thu Jun 16, 2016 2:34 pm
by Matt Simoncavage

Great, that worked. I have one more similar question.

In JQuery, I was able to map a value from the database to an image source and used the following javascript to force it to be a certain image if the value was blank:

if (value === undefined) {
return '../img/Placeholder.png';
} else {
return value;
}

Is there a way to do this in Ionic? The reason for this is that I have an image that displays the user's avatar, but if that user does not have an avatar I'd like to display a generic placeholder instead. Currently, I'm receiving a broken image if the value is blank.


Hiding 'undefined' text in Ionic

Posted: Thu Jun 16, 2016 6:42 pm
by Serhii Kulibaba

Yes, it is possible. Please use JS below for that:

pre$scope.myVariable = success.data.avatar || "../img/Placeholder.png'";/pre

here myVariable - name of the variable you need to set
avatar - response parameter, which might be empty


Hiding 'undefined' text in Ionic

Posted: Fri Jun 17, 2016 9:36 pm
by Matt Simoncavage

Hi again Sergiy, thanks for your reply. I'm just a bit confused on where to run that code. Do I apply it to the mapping, of to the init scope. Also, the response parameter if a field of a pointer. So would I just write it like this?:

success.data.Pointer.Avatar


Hiding 'undefined' text in Ionic

Posted: Tue Jun 21, 2016 6:19 am
by Serhii Kulibaba

Please use that JS code on the function "then". What parameter from the "avatar" collection do you want to use? Please show use the collection structure.