I want to customize my alerts in Ionic 2. I know that I can do it globally in the variables.scss, but I want to modify a specific one, in a specific page.
I tried cssClass in the alert code, I tried other different things, that work, but globally, not for a specific one.
Is there any way to do it??
Thanks!!
Just add any name you want in cssClass of alert as i named alertCustomCss
Adding Styles to alertCustomCss class
View Image after applying above style => Image Link
Adding the styles in
app.css
and calling it inpage.ts
In App.css
Edit all your
AlertController.create
methods to look like this:And add this to
app.scss
:If you created your specific page (let's call it
Sample1
) with the ionic CLI commandionic g page Sample1
, you will find in your project a directory called Sample1 with 3 files:Sample1.html
,Sample1.ts
andSample1.scss
.In
Sample1.scss
you will find:In that place you must define your custom css class or redefine the ionic element style and all your styles will have scope only onto the Sample1 page.
Hope this could help you
UPDATE
As Duannx mentions the alert components are not child of your page so if you put the css class into the specific page .scss file it will not be applied to the alert but if you put it into
app.scss
it will be applied. So this is an example:app.scss
Sample1.html
Sample1.ts
Now you will see that the button "Alert" will show a customized alert while the button "Alert2" will show the alter with the default css style
Though this is coming from Ionic 3, but you could always put the style outside of the
page-something
block from your something.scss file if you still want to keep local changes in your local files instead of the app.scss.