1
我已經使用NgForm創建了一個表單併爲其添加了一些控件。該表單用於概念的基本聊天證明。Angular2 RC1更新controlGroup中的控制值
當用戶發送消息時,我需要將消息輸入的值重置爲空,以便他們開始輸入下一條消息。但是,我無法找到任何有關如何更新控件價值的文檔或信息。
我已經嘗試了各種東西,但沒有什麼工作......
這裏的一些事情,我已經試過。
sendMessage(formValues) {
formValues.message = ''; // This works but the view doesn't update so there is evidently no binding or observers attached.
formValues.message.value = ''; // This throws an error that type string doesn't value defined
formValues.message.val(''); // This throws an error that type string doesn't contain a method val()
formValues['message'] = '' // This works but the view doesn't get updated so there is evidently no binding/observers here.
formValues.message.updateValue(''); // This also throws an error that type string doesn't have a updateValue() method.
}
繼承人的視圖模板:
<form name='chat-form' (ngSubmit)='sendMessage(messageForm.value)' #messageForm='ngForm'>
<input class='message-body' ngControl='message' placeholder='Enter your message'/>
<button type='submit'>Send</button>
</form>
必須有辦法做到在窗體上這樣的基本技術動作如更新從控制器或模型中的價值,但到目前爲止,我已經幹了。
formValues被一個ControlGroup? – Blacksonic
是的,我已經添加了上面的視圖模板代碼,以顯示如何通過ngForm指令創建ControlGroup – efarley