0
我想創建一個指令與input
。此input
可能可能需要required
屬性。如何將「required」屬性動態添加到指令模板?
例如
<my-input name="test" required/>
或
<my-input name="test" />
現在,在我的指導我有這樣的一個模板:
<input type="text" name="{{name}}" />
現在,如果我添加驗證工作正確的模板內required
屬性。但我當然需要動態地添加它。所以我使用下面的代碼來添加屬性。
if (attributes["required"] != undefined)
{
var input = element.find("input");
input.prop("required", true);
}
我曾嘗試把這個代碼link
和pre compile
內部和HTML渲染正確,但是,這並不工作。
我是新的指令,所以我顯然是在討論這個錯誤。
我應該如何添加required
屬性?