如何绑定到单选按钮angular2 6公测 [英] How to bind to radio buttons in angular2 beta 6

查看:167
本文介绍了如何绑定到单选按钮angular2 6公测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎样才能实现单选按钮处于测试阶段6约束力?

How does one achieve radio button binding in beta 6?

我发现测试0(请参阅<一个很大的plnkr href=\"http://plnkr.co/edit/aggee6An1iHfwsqGoE3q?p=$p$pview\">http://plnkr.co/edit/aggee6An1iHfwsqGoE3q?p=$p$pview),但是当我尝试将其更新到公测6可怕它打破(见 http://plnkr.co/edit/ voU933?p = preVIEW )。

I found a great plnkr for beta 0 (see http://plnkr.co/edit/aggee6An1iHfwsqGoE3q?p=preview), but when I try to update it to beta 6 it breaks horribly (see http://plnkr.co/edit/voU933?p=preview).

我接过一看犯了添加内置支持无线选项(请参阅https://github.com/angular/angular/commit/e725542),这给这个例子

I took a look at the commit that added built-in support for radio options (see https://github.com/angular/angular/commit/e725542), which gives this example

@Component({
  template: `
    <input type="radio" name="food" [(ngModel)]="foodChicken">
    <input type="radio" name="food" [(ngModel)]="foodFish">
  `
})
class FoodCmp {
  foodChicken = new RadioButtonState(true, "chicken");
  foodFish = new RadioButtonState(false, "fish");
}

但我的努力,使这项工作到目前为止最终挺喜欢我的失败plnkr。

but my attempts to make that work have so far ended up quite like my failed plnkr.

推荐答案

若干问题。

使用&LT;脚本SRC =HTTPS://$c$c.angularjs.org/2.0.0-beta.7/angular2.min.js&GT;&LT; / SCRIPT&GT; 出现异常。我被删除`分钟摆脱它?

Using <script src="https://code.angularjs.org/2.0.0-beta.7/angular2.min.js"></script> caused an exception. I got rid of it by removing `min.?

无线电结合 {检查:真正}值而不是。这显然​​是一个错误,并可能是相同的,因为这些

The radio binds the value {checked: true} instead of value. This is obviously a bug and probably the same as these

  • https://github.com/angular/angular/issues/7282
  • https://github.com/angular/angular/issues/7051
  • https://github.com/angular/angular/issues/7051
  • https://github.com/angular/angular/issues/3104

我把它用一个丑陋的解决办法工作。见<一href=\"https://plnkr.co/edit/988PSJKXCfrUXfLOGgyg?p=$p$pview\">https://plnkr.co/edit/988PSJKXCfrUXfLOGgyg?p=$p$pview

I got it working with an ugly workaround. See https://plnkr.co/edit/988PSJKXCfrUXfLOGgyg?p=preview

    <input type="radio" [ngModel]="{checked: model.sex == 'male'}" (ngModelChange)="model.sex='male'"  name="sex" value="male">Male<br>
    <input type="radio" [ngModel]="{checked: model.sex == 'female'}"  (ngModelChange)="model.sex='female'" name="sex" value="female">Female

这篇关于如何绑定到单选按钮angular2 6公测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆