Similar to @sebaferreras you can use the names listed in Platform Name, but I will suggest using it in conjunction with the showWhen
attribute.
The showWhen
attribute takes a string that represents a platform or
screen orientation. The element the attribute is added to will only
be shown when that platform or screen orientation is active.
This approach encapsulates the Platform class logic meaning you don't need to do anything in the Page.ts file, the only code you need to worry about will be in the HTML.
Example
If you want certain code to only be visible on a tablet screen
<div showWhen="tablet">
All content inside here will be visible on tablet devices
</div>
Se the ShowWhen documentation for more information. They also offer a HideWhen attribute too.
Note
As mentioned in the comments below
- The
showWhen
approach will just apply the display: none;
property
to the element which means your HTML will still be rendered
regardless of the type of device.
- If you take the
*ngIf
approach it will only load the HTML content
if it meets the rules.
Performance wise *ngIf
may be the better option for you, however in other scenarios showWhen
may be more favourable (I'm trying to keep this generic for other readers).