ngSwitch中的ng模型不起作用



我有发送JSON格式计算值到服务器的表单。但我不明白为什么只有ngSwitch内部的ng-model不发送JSON数组。我认为ng-model应该在ngSwitch中使用$parent工作。但是angular似乎还需要更多的东西。

这是我的表格

    <form ng-app="SaunaDoorCalc" ng-controller="SaunaDoorCalcController" class="calculator" name="calculator">
....
<tr><td>Result</td> 
    <td ng-switch-default ng-model="$parent.doorsize">@{{selectedSizeSwitch}}, @{{selectedStandardSize.label}}</td>
    <td ng-switch-when="non-standard" ng-model="$parent.doorsize">@{{selectedSizeSwitch}}, @{{DoorSizeB}}x@{{DoorSizeH}}</td>   
    <td ng-switch-default ng-model="$parent.baseprice">@{{selectedStandardSize.price}}</td>
    <td ng-switch-when="non-standard" ng-model="$parent.baseprice">@{{DoorSizeB*DoorSizeH*5000/1000000}}
    </td>
</tr>
....
</form>

和我的脚本

angular
  .module('SaunaDoorCalc',[])
    .controller('SaunaDoorCalcController', function($scope, $http) {
    $scope.outerScope = {};
    $scope.formData = {};
    .....
    $scope.submit = function(isValid) {
      if (isValid) {
          $http.post($scope.url, 
            {
              "calcname": "saunadoor", 
              "doorsize": $scope.doorsize, 
              "baseprice": $scope.baseprice, 
              "glass": $scope.selectedGlass, 
              "korobka": $scope.selectedKorobka, 
              "petli": $scope.selectedPetli, 
              "dekor": $scope.selectedDekor, 
              "dostavka": $scope.selectedDostavka,
              "montazh": $scope.montazh, 
              "name": $scope.name, 
              "tel": $scope.tel, 
              "email": $scope.email, 
              "msg": $scope.msg, 
            }).
                        success(function(data, status) {
                            console.log(data);
                            $scope.status = status;
                            $scope.data = data;
                            $scope.result = data; 
                        });
              $scope.name = null;
              $scope.tel = null;
              $scope.email = null;
              $scope.msg = null;
              $scope.DoorSizeB = null;
              $scope.DoorSizeH = null;
              $scope.calculator.$setPristine();
              $scope.message = 'Заказ отправлен. В ближайшее время мы с вами свяжемся.'; 
            }else{
              $scope.message = 'Заполните обязательные поля формы!'; 
            }
        }
  });

ng-model不绑定td元素,应该使用ng-bind代替

https://docs.angularjs.org/api/ng/directive/ngModel

ngModel指令使用NgModelController将input、select、textarea(或自定义表单控件)绑定到作用域上的一个属性上,这个属性是由该指令创建和公开的。

相关内容

  • 没有找到相关文章

最新更新