AngularJS - Server side validation and client side forms

前端 未结 8 751
忘了有多久
忘了有多久 2020-12-12 11:40

I am trying to understand how to do the following things:

What is the accepted way of declaring a form. My understanding is you just declare the form in HTML, and ad

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-12 12:05

    By default, the form is submitted normally. If you don't provide a name property for each field in the form then it won't submit the correct data. What you can do is capture the form before it submitted and submit that data yourself via ajax.

    And then in your $scope.onSubmit() function:

    $scope.onSubmit = function() {
      var data = {
        'name' : $scope.item.name
      };
      $http.post(url, data)
        .success(function() {
        })
        .failure(function() {
    
        });
    };
    

    You can also validate the data by setting up required attributes.

提交回复
热议问题