【问题标题】:Angularjs bind ng-model dynamically to an valueAngularjs 将 ng-model 动态绑定到一个值
【发布时间】:2014-06-21 16:03:40
【问题描述】:

我想动态更改 ng-model 值的引用。例如,我可以这样做:

$scope.test = {
  normalStringValue1 : [],
  normalStringValue2 : []
}

if($scope.status == 'A') {
  $scope.values= $scope.test.normalStringValue1;
} else {
  $scope.values= $scope.test.normalStringValue2;
}

<input ng-model="values" type="radio" name="xValues" ng-value="header.id | num">

这可行,但我的问题是,仅当“normalStringValue1 或 2 是一个数组!如果正常字符串值看起来像这样:

$scope.test = {
  normalStringValue1 : null,
  normalStringValue2 : null
}

我只想保存一个像normalStringValue1 : 'Hello' 这样的字符串,引用不会正确更改,为什么会这样?我该如何解决这个问题?

【问题讨论】:

    标签: angularjs angularjs-directive angularjs-scope angular-ngmodel


    【解决方案1】:

    试试这个

    $scope.test = {
      normalStringValue1 : '',
      normalStringValue2 : ''
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-13
      • 1970-01-01
      • 2021-01-19
      相关资源
      最近更新 更多