Join egghead, unlock knowledge.

Want more egghead? It's 45% off for a limited time only!

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

Unlock All Content for 45% Off

Already subscribed? Sign In

Save 45% for a limited time.

Get access to all courses and lessons on egghead today.

Autoplay

    Build your first page component with Ionic 2

    Mike HartingtonMike Hartington

    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.

    angularAngular
    2 - 6
    ionicIonic
    Code

    Code

    Become a Member to view code

    You must be a 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
    Transcript

    Transcript

    00:00 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.

    00:23 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.

    00:39 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.

    00:54 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.

    01:13 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.

    01:41 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.

    Discuss

    Discuss