是否有等同于 Angular 2 的局部模板变量的 Aurelia?
Is there an Aurelia equivalent to Angular 2's local template variables?
在 Angular 2
中,您可以创建 local template variables 以更轻松地访问 html 中的元素。
<input #name type="text">
<button (click)="submit(name.value)">Submit</button>
Aurelia 中是否有与此等效的功能?
是的 - 这是 ref
属性。
举个例子:https://gist.run?id=7d1140ba81542bf7a2609a0d09fcdea5
app.html
<template>
<input ref="name">
<button click.delegate="submit(name.value)">Click Me</button>
</template>
app.js
export class App {
submit(name) {
alert(name);
}
}
使用ref
<input type="text" ref="name" />
<button click.delegate="submit(name.value)">Submit</button>
http://aurelia.io/docs#/aurelia/framework/1.0.0-beta.1.1.4/doc/article/cheat-sheet/5
在 Angular 2
中,您可以创建 local template variables 以更轻松地访问 html 中的元素。
<input #name type="text">
<button (click)="submit(name.value)">Submit</button>
Aurelia 中是否有与此等效的功能?
是的 - 这是 ref
属性。
举个例子:https://gist.run?id=7d1140ba81542bf7a2609a0d09fcdea5
app.html
<template>
<input ref="name">
<button click.delegate="submit(name.value)">Click Me</button>
</template>
app.js
export class App {
submit(name) {
alert(name);
}
}
使用ref
<input type="text" ref="name" />
<button click.delegate="submit(name.value)">Submit</button>
http://aurelia.io/docs#/aurelia/framework/1.0.0-beta.1.1.4/doc/article/cheat-sheet/5