Angular JS 隐藏字段:保存带有条件的 ng-model

Angular JS hidden field : saving ng-model with condition

我有一个隐藏字段,用来标识指令的类别

如何将数据绑定为:

<input type = "hidden" ng-model="category = category.option.name == 'By Count Range' ? 'byCount' : 'byRate' ">

以上代码在编译时不可赋值。

我该如何解决这个问题?

我不确定我的代码,但我需要执行该条件检查。

因此,您有两个选项:按计数范围或按比率,并根据您选择的选项更改 .对吧?

然后,您可以在模板中执行此操作:

<select name='...' ng-model='...' ng-change='updateOptions()'>

并在您的控制器中:

$scope.updateOptions = function () {
    if ($scope.category.priceOrTransactionOption == 'By Count Range'){
      $scope.categoryOptions = $scope.category.byCountRange.tiers
    }else{
      $scope.categoryOptions = $scope.category.byRate.tiers;
    }
};

并在 html 中:

<div ng-repeat="categoryObject in categoryOptions track by $index">

<div>