Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to set dynamic picker color from ts file #18

Open
melalitesh opened this issue Apr 16, 2019 · 3 comments
Open

how to set dynamic picker color from ts file #18

melalitesh opened this issue Apr 16, 2019 · 3 comments

Comments

@melalitesh
Copy link

Hi,

I want to set the color of picker from .ts file, but changing the hexstring doesn't change the picker color.

Please suggest

@dolanmiu
Copy link
Owner

Show me your code

@melalitesh
Copy link
Author

melalitesh commented Apr 17, 2019

getColorFromRGB(){
		let hex = this.rgbToHex(this.coolColor.rgb.red, this.coolColor.rgb.green, this.coolColor.rgb.blue);
		this.coolColor.hexString = '#'+hex;
		this.coolColor.rgb.red = Number(this.coolColor.rgb.red)
		this.coolColor.rgb.green = Number(this.coolColor.rgb.green)
		this.coolColor.rgb.blue = Number(this.coolColor.rgb.blue)
		let hsl = this.rgbToHsl(this.coolColor.rgb.red, this.coolColor.rgb.green, this.coolColor.rgb.blue);
		this.coolColor.hsl.hue = hsl[0];
		this.coolColor.hsl.saturation = hsl[1];
		this.coolColor.hsl.lightness = hsl[2];
	}
<ng-color-box (ngModelChange)="colorChange($event)" [(ngModel)]="coolColor" startHex="coolColor.hexString"></ng-color-box>

@dolanmiu
Copy link
Owner

Try setting everything in one go, like this:

getColorFromRGB(){
		let hex = this.rgbToHex(this.coolColor.rgb.red, this.coolColor.rgb.green, this.coolColor.rgb.blue);


		this.coolColor = {
                    hexString: ...,
                    rgb: {
                       red: ...
                    }
               }

this look a little bit wrong to me:

this.coolColor.rgb.red = Number(this.coolColor.rgb.red)

It is using itself to set itself? Inception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants