0

Angular 的 renderer2 不会应用线性渐变 CSS。谁能看到我错过了什么?

export class AppComponent implements OnInit {

  constructor(private renderer: Renderer2, private elementRef: ElementRef) {}

  public ngOnInit(): void {
    this.renderer.setStyle(
      this.elementRef.nativeElement,
      "background",
      "linear-gradient(rgba(253,92,99,1), rgba(144,255,0,1) 30%);" 
      // "red" // works, so does this rule in CSS
    );
  }
}

这是一个stackblitz repro

4

1 回答 1

2

本,

梯度规则中的最后一个分号会产生错误:它的工作方式是:

    this.renderer.setStyle(
      this.elementRef.nativeElement,
      "background",
      "linear-gradient(rgba(253,92,99,1), rgba(144,255,0,1) 30%)" //no semicolon in the end
    );
于 2020-11-19T20:17:26.023 回答