0

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?

1
  • Can you add more code? Where do you write it? Commented Aug 2, 2017 at 20:18

1 Answer 1

1

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>

Plunker Example

See also

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.