AngularJS - Server side validation and client side forms

前端 未结 8 758
忘了有多久
忘了有多久 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:00

    If you choose ngResource, it would look like this

    var Item = $resource('/items/');
    $scope.item = new Item();
    $scope.submit = function(){
      $scope.item.$save(
        function(data) {
            //Yahooooo :)
        }, function(response) {
            //oh noooo :(
            //I'm not sure, but your custom json Response should be stick in response.data, just inspect the response object 
        }
      );
    };
    

    The most important thing is, that your HTTP-Response code have to be a 4xx to enter the failure callback.

提交回复
热议问题