I need to add a new named color to Ionic2. If I add a new named color to the existing named colors list in
variable.scss file, all screens get blank when I build my app with
// Named Color Variables
// Named colors makes it easy to reuse colors on various components.
// It's highly recommended to change the default colors
// to match your app's branding. Ionic uses a Sass map of
// colors so you can add, rename and remove colors as needed.
// The "primary" color is the only required color in the map.
// <----- I cannot add a new color here, because if I do this
// all screens get blank when I build my app with `--prod` switch
I need new named colors because I want to set my navbar color dynamically by using the
Hmm, that’s interesting. I haven’t had a problem with adding a new colour to variables.scss like this:
pridark: #D5792E, // <-- New Colour
And in a html file I use it as you normally would:
Is it possible that your myTSObject.myColorFromDatabase is going out of scope somehow? In a --prod build, are you able to output myTSObject.myColorFromDatabase to the console.log to see if it exists?
Can you create production builds with --prod switch?
Yes, my production build works with the new colour. See my edit above about console.log and scope.
Bind the Ionic property to your variable if you’re using an Ionic component. So
[color]="variableName" instead of what you are doing right now. It’s easy to mix Ionic syntax with Angular syntax, but they are not the same. That said, the name of your variable worries me, because if you’re trying to pull the color from a database at runtime, there might be more problems than what you are describing.
Nope, not in a --prod build. But in non --prod build my app shows all colors according to my
The name options I give the user to save in the database come from a select component. They are the exact names in my
variables.scss file. In a non
--prod build it works ok.
I noticed that you have added your new color name just under the
primary name. I just added only one name under the primary and it works! I am going to try to add more names now… Maybe the position matters!
Wow… if that’s the case then there’s definitely a problem with the scss parser. I’m glad you got it to work though. Let me know if adding more colours still works - I’m curious.
Edit: I just tried adding a new colour to the end of the list as you had it, and yep - it breaks! There’s definitely a problem with the parser or something.
I have just added 1 more name and it works! Now I am going to add all my new twenty named colors.
Awesome - I’m glad it’s working for you. Also, see my edit above.
Awesome! Thank you for your help!
No problem for me to add at the end, don’t forget “,”
And… does this work for you in a production build as cristianguedes stated, using --prod?
Sometimes position matters. Sometimes it does not. I have also noticed that quantity matters. Try to add as many color variables as below (and then try to run a
And yep, I am not forgetting “,”.
So Cristian, is adding all of these colours failing for you at some point? I try to limit my apps to about 6 colours for the GUI so I don’t have as many in the list as you do. If it’s passing at a certain amount of colours and failing when the list gets too long then I have a feeling this is an issue that has to be raised to the ionic team.
Yes, it is BradBurns! I was able to add only 14 additional color variables. If I try to add more than 14, all screens get blank after splash screen (if I run
ionic run android --prod). BTW, how can I raise an issue to Ionic team?
I’m pretty sure they use their GitHub repository to track issues here:
Don’t forget to search for a similar issue first before posting this as an issue to avoid creating a duplicate.
You’re welcome, Cristian. Glad I was able to help.