Reputation: 125
how to use a variable multicolors defined in typescript file in our template ?: -
I have tried like this -webkit-linear-gradient(135deg, {{multicolors}} 50%, lightgray 50%)
but not working , any solution?
Upvotes: 0
Views: 923
Reputation: 214017
I would create pipe like:
@Pipe({ name: 'safeStyle' })
export class SafeStylePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
transform(style) {
return this.sanitizer.bypassSecurityTrustStyle(style);
}
}
and then use it as follows
<div [style.background]="'-webkit-linear-gradient(135deg, ' + multicolors + ' 50%, lightgray 50%)' | safeStyle">
Test
</div>
See also
Upvotes: 1