Create Angular 2 Mobile Card based layouts with Ionic 2

Mike Hartington
InstructorMike Hartington

Share this video with your friends

Send Tweet
Published 6 years ago
Updated 4 years ago

Cards have become a common way to handle layout and display information in a easy-to-understand format. Ionic offers utility components that make creating cards straightforward. These components, like ion-card, ion-card-content, and ion-card-header are included in the framework to speed up the development process. There's no JavaScript behind these components, they're really just css driven.

[00:01] With the detail of our user being displayed in the detail page, we can start to use a card layout to better organize this information. A card is made up of a few components, an outer ion card wrapper, an inner ion card header, and then another inner ion card content.

[00:25] We can also reuse ion items inside of our card as well. For this card, we'll start off with an ion item instead of an ion card header. Inside of the item, we'll render the user's first name and the user's last name.

[00:42] We'll add an ion avatar, and place it on the left side of the item. Inside of the avatar, we'll add an image, and bind its source to the user's large image. With this item finished up, we'll use the ion card content to create a section of the card that has a little bit of padding. We'll add a few more ion items. Inside of the first one, we'll set up our bindings for the user's location.

[01:22] We'll also go ahead and add an ion icon to this item. The icon can be positioned on the left or the right side using the item-left or item-right attribute. Let's go ahead and fill out these last two ion items with the user's phone number and the user's email address.

[01:49] Now, when we save, we'll have the information displayed in a formatted card. Now, a nice thing about the ion card is that it has no built-in padding. This is why we use the ion card content for the main block of information. Since there's no padding, this means that you can do full background images with just a simple image tag.