我將一個Angular應用程序移植到Aurelia作爲學習練習,我不確定如何重新創建Angular ng變化行爲。Angular的ng-change的Aurelia版本
有一個元素,當改變的時候觸發一個javascript回調。我不知道如何在Aurelia做到這一點。或者我應該只使用HTML5?
我將一個Angular應用程序移植到Aurelia作爲學習練習,我不確定如何重新創建Angular ng變化行爲。Angular的ng-change的Aurelia版本
有一個元素,當改變的時候觸發一個javascript回調。我不知道如何在Aurelia做到這一點。或者我應該只使用HTML5?
將方法/表達結合於一個事件,使用event.delegate="expression"
,與像change
或input
實際的事件名稱替換「事件」。
下面是一個例子:https://gist.run?id=a3ced6a08842a421a715c7df068b41d5
app.html
<template>
<form change.delegate="changeCount = changeCount + 1"
input.delegate="incrementInputCount($event.target)">
<p>
This form has changed ${changeCount} times.
The input event has fired ${inputCount} times.
</p>
<input type="text" placeholder="type something...">
<input type="text" placeholder="type something...">
<input type="text" placeholder="type something...">
</form>
</template>
app.js
export class App {
changeCount = 0;
inputCount = 0;
incrementInputCount(inputElement) {
console.log(inputElement.value);
this.inputCount++;
}
}
注意:如果事件不起泡(例如聚焦/ blur),請使用event.trigger
並將綁定直接放在元素將觸發事件。例如,<input blur.trigger="doSomething()">
。
change.delegate="someViewModelMethod()"
這就是我從我的手機回答 –
我喝你的奶昔 –