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'') –