【发布时间】:2020-06-02 23:51:21
【问题描述】:
我想创建一些方法并从不同组件的 html 中调用它们。另一方面,How to call static method of other class in .html (not in .ts)? 有一些方法,但它很旧,我想知道 Angular 9 中是否有更好的方法来直接调用该方法。也可以使用共享服务并在该服务中定义共享方法,但我正在寻找另一种直接从 html 调用静态方法的方法。我该怎么做?
demoBase.ts:
export class DemoBase {
static demoMethod(id) {
//
}
}
那我想从另一个组件的html调用这个方法:
list.component.ts:
import { DemoBase } from '@pages/demoBase';
//other stuff (I do not want to create a method here to access base method)
list.component.html:
<div><span [ngClass]="DemoBase.demoMethod(record.Id)">{{record.Name}}</span></div>
【问题讨论】:
标签: angular typescript