首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >访问组件模板中的指令变量

访问组件模板中的指令变量
EN

Stack Overflow用户
提问于 2019-08-20 15:37:02
回答 1查看 41关注 0票数 0

我有这个指令=>

代码语言:javascript
复制
export class ThrottleClickDirective implements OnInit, OnDestroy {
    @Input() 
    throttleTime = 500;

    @Output() 
    throttleClick = new EventEmitter();

    public throttling = false;
    private clicks = new Subject();
    private subscription: Subscription;

    constructor() { }

    ngOnInit() {
        this.subscription = this.clicks.pipe(
            throttleTime(this.throttleTime)
        ).subscribe(e => {
            this.throttleClick.emit(e)
            this.throttling = false;   
        });
    }

    ngOnDestroy() {
        this.subscription.unsubscribe();
    }

    @HostListener('click', ['$event'])
    clickEvent(event) {
        event.preventDefault();
        event.stopPropagation();
        this.clicks.next(event);
        this.throttling = true;
    }
}

这是我的模板

代码语言:javascript
复制
    <button mat-button *ngFor="let button of buttons" 
        [ngClass]="[((button.className) ? button.className : ''), 'custom-popup-button']" 
        [disabled]="(button.type === 'confirmation')"
        appThrottleClick 
        (throttleClick)="button.action();" 
        [throttleTime]="500">
        {{button.text}}
    </button>

我想要禁用我的按钮,如果但throttling当前是真的(以便它显示点击已被考虑在内)。

有没有办法从模板中访问变量(在指令之外)

这个组件(按钮所在的组件)是一个通用组件,它根据设置而作为不同数量的按钮,所以我不能真正在它上面存储变量。最好的方法是在disablethrottling之间建立某种连接

EN

回答 1

Stack Overflow用户

发布于 2019-08-20 16:26:11

像这样的东西可能行得通

代码语言:javascript
复制
@HostBinding('class.myDisableClass') throttling:boolean;

在css中

代码语言:javascript
复制
.myDisableClass button{
   cursor: not-allowed;
   pointer-events: none;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57568754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档