I would like to have 1 per device template for views in angular2 and for some views there may be 1 for all the devices. Is it possible in angular2 based on the browser user-agent
There are plans but it has yet to be decided if it will actually be implemented.
Currently you can use media queries and for example ngSwitch
to show different parts of a view depending on the device or screen dimensions.
See also
You could use CSS @imports with media queries for this.
All you need to do is to create a separate CSS file for each device and then import it in your template style.
Example:
Angular2 component:
@Component({
selector: 'my-comp',
template: `...`,
styleUrls: ['./style.css']
})
In style.css
:
@import url("device1.css") screen and (min-width: 300px);
@import url("device2.css") screen and (min-width: 800px);
And then the device-specific styles in device1.css and device2.css.
See https://developer.mozilla.org/en/docs/Web/CSS/@import for details to CSS @imports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With