小编Lei*_*eix的帖子

如何从指令注入材质组件?

有没有办法使用 renderer2 从指令注入材质组件?

就我而言,我尝试制定一个指令,在垫子按钮中显示垫子进度旋转器。

例如,这是一个指令。这段代码所做的事情与我正在尝试做的事情类似。由于我在项目中使用 Angular Material,因此我想添加一个名为 mat-progress-spinner 的材质组件,而不是这个简单的 gif

@Directive({
  selector: '[appButtonLoader]'
})
export class ButtonLoaderDirective {
  img: HTMLImageElement;

  @Input() set appButtonLoader(value: boolean) {
  this.toggle(value);
}

constructor(private element:ElementRef) {
  this.img = document.createElement('img');
  this.img.src = 'https://www.winston.com/cached/40181/images/spinner-white.gif';
  this.toggle(this.appButtonLoader);
}

toggle(condition: boolean) {
  condition ? this.show() : this.hide()
}

show() {
  this.element.nativeElement.appendChild(this.img);
}

hide() {
  this.img.remove();
}
Run Code Online (Sandbox Code Playgroud)

}

stackblitz:https://stackblitz.com/edit/load-button-directive? file=app%2Fbutton-loader.directive.ts

angular-material

2
推荐指数
1
解决办法
1346
查看次数

标签 统计

angular-material ×1