I try to set the gradient on the component dynamically and get the following warning:
WARNING: sanitizing unsafe style value linear-gradient(#000,#00f) (see http://g.co/ng/security#xss).
Here's the minimum playback:
import { Component } from '@angular/core'; @Component({ selector: 'my-app', template: '<h1 [style.background]="(\'linear-gradient(#000,#00f)\')">My First Angular 2 App</h1>' }) export class AppComponent {}
My search engine tells me to use bypassSecurityTrustStyle , but I'm not happy with it until I find out
- Why is a linear gradient considered unsafe?
- Is this the intended behavior or just a bug with the current version of Angular 2.
- Is there a better way to do this without considering it unsafe?
This should be dynamic as I build the gradient line programmatically. I cannot use css classes for this.
css angular xss gradient
david
source share