【发布时间】:2020-02-01 02:15:53
【问题描述】:
我在 Medium (https://medium.com/@sub.metu/angular-fallback-for-broken-images-5cd05c470f08) 上发现了这个非常好的指令:
import {Directive, Input, HostBinding} from '@angular/core'
@Directive({
selector: 'img[default]',
host: {
'(error)':'updateUrl()',
'(load)': 'load()',
'[src]':'src'
}
})
export class ImagePreloadDirective {
@Input() src:string;
@Input() default:string;
@HostBinding('class') className
updateUrl() {
this.src = this.default;
}
load(){
this.className = 'image-loaded';
}
}
但是,TSlint 告诉我应该在第 4 行使用 HostBinding 而不是 host。但我没有找到可以帮助我实现这一点的文档。有人可以帮忙吗?
【问题讨论】:
标签: angular