Quieting "WARNING: sanitizing unsafe..." in Angular2 RC

6 views
Skip to first unread message

Forrester Cole

unread,
Jun 28, 2016, 11:32:16 AM6/28/16
to Angular2
Hi,
   I'm working on updating my code to the new Angular2 RC. I notice that I now get a bunch of warnings that look like:

WARNING: sanitizing unsafe style value background-color: #1E1514

The offending angular code looks like:

<div *ngFor="let color of colors"
    class="color-swatch"
    style="background-color: {{color}}"
</div>

where colors is a list of strings set in the accompanying code. I'm fine with the sanitization, but is there a way to explicitly sanitize these values so that I don't get spammed with the warning? Thanks,

Forrester

Michiel Kikkert

unread,
Jul 11, 2016, 6:56:04 AM7/11/16
to Angular2
Did you end up resolving this?

If not, maybe using 

<div *ngFor="let color of colors"
    class="color-swatch"
    [style.backgroundColor] = "color"
</div>

is a solution?

Forrester Cole

unread,
Jul 11, 2016, 10:01:17 AM7/11/16
to Angular2
I ended up using this line, which fixed it:

[ngStyle]="{'background-color': color}"

Maybe that works out to the same thing as your code, not sure. Thanks,

Forrester

Michiel Kikkert

unread,
Jul 11, 2016, 10:07:01 AM7/11/16
to Angular2
Ah great, yeah that was also a possibility.
Reply all
Reply to author
Forward
0 new messages