Ionic 2 data binding with function?


For a list of items, depending on the value of a certain key in the item, I’d like to show different images. Is this possible in Ionic 2 through some kind of interpolation/data binding using a function?

For example:

items = [
    {thing: "abc", state: "1"},
    {thing: "xyz", state: "2"},

and display the item list as

    <ion-item *ngFor="#item of items">
        <img src=getImage({{item.state}})>    <---- Is this possible?

where getImage(state) function would return the path to the image file depending on the value of state.


Yes, it’s possible, but this is the correct way to do it:

<img src="{{getImage(item.state)}}" />