Matt Simoncavage
Posts: 0
Joined: Thu Jun 04, 2015 7:10 pm

Hiding 'undefined' text in Ionic

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Hiding 'undefined' text in Ionic

Hello Matt,

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

Matt Simoncavage
Posts: 0
Joined: Thu Jun 04, 2015 7:10 pm

Hiding 'undefined' text in Ionic

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".

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Hiding 'undefined' text in Ionic

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

Matt Simoncavage
Posts: 0
Joined: Thu Jun 04, 2015 7:10 pm

Hiding 'undefined' text in Ionic

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Hiding 'undefined' text in Ionic

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

Matt Simoncavage
Posts: 0
Joined: Thu Jun 04, 2015 7:10 pm

Hiding 'undefined' text in Ionic

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Hiding 'undefined' text in Ionic

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

Matt Simoncavage
Posts: 0
Joined: Thu Jun 04, 2015 7:10 pm

Hiding 'undefined' text in Ionic

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Hiding 'undefined' text in Ionic

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.

Return to “Issues”