Ram*_*rva 6 html javascript templates angular
我正在尝试读取单选按钮值 - 以角度2,
的index.html
<input type="radio" id="options1" name="function" value="create">
<input type="radio" id="options2" name="function" value="continue">
Run Code Online (Sandbox Code Playgroud)
index.ts
@Component({
selector: 'function',
templateUrl: './client/components/function/index.html',
styleUrls: ['./client/components/function/index.css'],
providers: [],
directives: [ROUTER_DIRECTIVES]
})
Run Code Online (Sandbox Code Playgroud)
我需要根据是否创建或继续单选按钮值在html中显示div.
我尝试过的:
document.getElementById- checked未检测到属性获取打字稿文件中单选按钮的值.model.function通过model在打字稿中定义a 来读取值.model显然,无法访问变量![(ngModel)]- 也没用.请为此建议一个转机.
模板:
<input type="radio" id="options1" [(ngModel)]="myRadio" value="create">
<input type="radio" id="options2" [(ngModel)]="myRadio" value="continue">
Run Code Online (Sandbox Code Playgroud)
然后myRadio在组件中定义一个变量并将其初始化为:
myRadio: string = ''
此变量将获得所选值.
并且,不要使用javascript来控制Angular2中的DOM元素,这是针对angular2哲学的
| 归档时间: |
|
| 查看次数: |
11498 次 |
| 最近记录: |