[英]Angular2 event binding, can it be done without '(' & ')', Property binding can it be done without '[' & ']'
我想知道是否有任何方法可以實現事件和屬性綁定而不使用括號或括號 ?
參考: https : //angular.io/docs/ts/latest/guide/template-syntax.html#!#event-binding
<input [value]="currentHero.firstName"
(input)="currentHero.firstName=$event.target.value" >
編輯:
功能:
getDomElement(model:Object){
//...some logic to control the elemet generation
return {text-type-InputElement};// ..only returns elemnts(eg: <input type="text"/>)
}
var type = getDomElement(elem).type; // .. will give us TEXT
var tagName = getDomElement(elem).tagName;//.. will give us INPUT
使用上面返回的DomElement,我試圖執行element.setAttribute(“[(ngModel)]”,“model.firstName”) 。 這是不可能的,任何替代方案都可以實現這一點。
<input bind-value="currentHero.firstName"
on-input="currentHero.firstName=$event.target.value" >
請參閱https://angular.io/docs/ts/latest/guide/template-syntax.html (搜索“canonical”)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.