我坚持使用该指令。尝试通过自定义指令为按钮添加“ mat-raised-button”和“ color”。但这没有用。请帮助我工作。代码在这里,
import { Directive, ElementRef, Renderer2, HostListener, AfterViewInit } from '@angular/core';
import { MatRipple } from '@angular/material';
import { MatRipple } from '@angular/material';
@Directive({
selector: '[appButton]',
providers: [MatRipple]
})
export class ButtonDirective{
constructor(el: ElementRef, renderer: Renderer2, ripple: MatRipple) {
renderer.setAttribute(el.nativeElement, 'mat-raised-button', '');
renderer.setAttribute(el.nativeElement, 'color', 'primary');
}
}
放置属性,但是如上所述,它不会初始化预期的样式:
import { Directive, ElementRef, Renderer2 } from "@angular/core";
@Directive({
selector: '[appButton]'
})
export class ButtonDirective {
constructor(
private _elRef: ElementRef,
private _renderer: Renderer2,
) {
this._renderer.setAttribute(this._elRef.nativeElement, 'mat-raised-button', '');
this._renderer.setAttribute(this._elRef.nativeElement, 'color', 'primary');
}
}
有任何建议或新闻吗? (使用角/角材料9)