AngularJS form and null/empty values

前端 未结 4 932
一整个雨季
一整个雨季 2021-02-15 11:20

I am working with a somewhat dynamic AngularJS form. In other words, I am able to add rows of input fields, etc. So my approach was to start with a $scope.formData

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-15 11:52

    Added Watcher on formData,

    $scope.$watch('formData',function(n,o){
          if(typeof $scope.formData.title !== 'undefined' && $scope.formData.title === "" ){
            delete $scope.formData.title;
          }
    },true);
    

    Updated fiddle: https://jsfiddle.net/1ua6oj5e/6/

    For all the dynamic fields you should use angular form validation, you should see this: https://docs.angularjs.org/guide/forms

提交回复
热议问题