Angularjs - simple form submit

前端 未结 5 1271
滥情空心
滥情空心 2020-12-02 08:41

I am going through learning curve with AngularJs and I am finding that there are virtually no examples that serve real world use.

I am trying to get a clear understa

5条回答
  •  渐次进展
    2020-12-02 09:28

    var app = angular.module( "myApp", [] );
    
    app.controller( "myCtrl", ["$scope", function($scope) {
    
        $scope.submit_form = function(formData) {
    
            $scope.formData = formData;
    
            console.log(formData); // object
            console.log(JSON.stringify(formData)); // string
    
            $scope.form = {}; // clear ng-model form
    
        }
    
    }] );
    
    
    
    Firstname:
    Lastname:


    Firstname: {{ form.firstname }}

    Lastname: {{ form.lastname }}

    Submit Form: {{ formData }} 

    Codepen

提交回复
热议问题