Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Build your first page component with Ionic 2

    2 - 6

    The simplest way to display data in an app is with a simple listview. This list will go over how items work and how to place certain elements in ion-items position slots.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    In our main page component, home.ts, let's add some mock data to start working with. This is just some content copied from the random user API. We'll start off by just rendering this content in a simple pre-tag and then pass it through Angular's json filter.

    A common way to display all of this information is by creating an ordered list, similar to a phone's contact list. We'll start off by adding the ion list tag and inside of that we'll create a single ion item.

    We could just render out the first name and the last name and call it a day, but Ionic adds a few more components to make the list more interesting. We can start off by creating an ion avatar element inside of our item.

    Inside of that we can place an image tag and then set its source to the smallest image provided. The last bit we need to add is to tell the avatar if it should go on the left or if it should go on the right. To set this, we'll add itemRight or itemLeft on the element.

    If an avatar doesn't fit your style you can switch them out for thumbnails, which are squares instead of circles. For our list avatars will do just fine, so we'll switch back to them. We'll move down to the closing ion item tag and add the person's phone number using ion note. Then we'll set the position using the itemRight property.

    What you may notice is that this list looks very material-design and that's on purpose. For the browser Ionic will default to a material-design look and feel. If we wanted to mimic iOS we could open up a new tab, go to the same URL, and actually attach a gray parameter of ionicplatform=iOS and we would get a very iOS-looking design.