I'm trying to set a gradient on a component dynamically and am getting the following warning:
WARNING: sanitizing unsafe style value linear-gradient(#000,#00f) (see http://g.co/ng/security#xss).
Here's a minimal reproduction:
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 googling tells me to use bypassSecurityTrustStyle
but I'm not happy doing that until I know
- Why is linear gradient considered unsafe?
- Is this intended behaviour or just a bug with the current version of Angular 2.
- Is there a better way to do this without it being considered unsafe?
This does have to be dynamic as I'm building the gradient string programatically. I can't use css classes for this.