4
我想讀的單選按鈕值 - 在角2,閱讀單選按鈕值 - 角2
的index.html
<input type="radio" id="options1" name="function" value="create">
<input type="radio" id="options2" name="function" value="continue">
index.ts
@Component({
selector: 'function',
templateUrl: './client/components/function/index.html',
styleUrls: ['./client/components/function/index.css'],
providers: [],
directives: [ROUTER_DIRECTIVES]
})
我需要根據單選按鈕值是否創建或繼續在html中顯示div。
我已經試過什麼:
- 抓取的單選按鈕的值在使用
document.getElementById
將輸出文件 - 沒有得到檢測的性質checked
。 - 通過在打字稿中定義
model
,使用model.function
讀取該值。無法訪問model
變量,顯然! - 嘗試使用
[(ngModel)]
- 也沒有工作。
請爲此建議一個週轉。
我試過的建議,但我發現了,說'不能讀取屬性「值」一個HTML錯誤未定義的。另外,如果我不應該使用Javascript修改DOM元素,建議我如何使用Angular 2來做到這一點。 –
你需要在你的組件的構造函數中初始化變量: 'myRadio:string =''' –
(或者把默認值例如'myRadio:string ='create'') –