我正在尝试读取单选按钮值 - 以角度 2 表示,
索引.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.function
通过定义一个model
在打字稿中。无法访问model
变量,显然!
- 尝试使用
[(ngModel)]
- 那也没用。
请为此提出周转建议。
模板:
<input type="radio" id="options1" [(ngModel)]="myRadio" value="create">
<input type="radio" id="options2" [(ngModel)]="myRadio" value="continue">
然后定义一个myRadio
组件中的变量并像这样初始化它:myRadio: string = ''
该变量将获得所选值。
and, do not在 Angular2 中使用 javascript 控制 DOM 元素,这违背了 Angular2 的哲学
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)