我正在尝试在我的 ionic 2 选项卡中调用我在 typescript/Angular 2 中编写的函数。我对打字稿很陌生,所以不完全知道它是如何工作的。
当我试图调用该函数时,控制台给出一个错误,指出我编写的 randomise() 函数不是函数......
这是我放置代码的 JSFiddle 文件。“卡片”部分完美无缺,它只涉及我的随机功能。HTML:
<button fab class="card-subtitle">{{randomise(100,10000) | currency :'USD' : true}}</button>
TS:
export class randomNumber {
public number: number;
constructor (min: number, max: number){
this.randomise(min, max)
}
randomise(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
}