在angular2中向数组添加元素

时间:2017-02-02 00:21:38

标签: angular typescript

我想向数组中添加元素。我实际上传递了多个单选按钮的值 这就是我写的

changeValue(params) {
let yesvalue:any[] = [];
 let novalue:any[] = [];

let param_new_name = params.value.split('-')[0];  //0 is the value which is 
                                                   //similar to yes and no radios
if(params.value.split('-')[1] == "no"){
  novalue.push(param_new_name);
  var yes = yesvalue.indexOf(param_new_name);
  if (yes > -1) {
    yesvalue.splice(yes, 1);
  }

}else if(params.value.split('-')[1] == "yes") {

  yesvalue.push(param_new_name);
  var no = yesvalue.indexOf(param_new_name);
  if (no > -1) {
    novalue.splice(no, 1);
  }

}

console.log(params);
console.log("yes values are"+yesvalue); 
console.log("no values are"+novalue);  

}

传递的param的示例包含

<input type="radio" ng-reflect-value="11-no" value="11-no" 
  ng-reflect-name="new_0" name="new_0">

另一个

<input type="radio" ng-reflect-value="11-no" value="12-no" ng-reflect-name="new_0" name="new_0">  

单选按钮的值是动态的,它们具有不同的值,不断变化

例如12-yes13-yes12-no

在bove控制台日志中,值始终为空,我错了

0 个答案:

没有答案