你如何在AngularJS中提交表格?

时间:2013-11-03 22:52:38

标签: javascript angularjs angularjs-scope

我有一个简单的表格,你选择一种颜色并输入数量。当您单击“提交”按钮时,我想将index.html部分替换为submitted.html部分,并使用从表单提交的信息。在SubmittedCtrl我将使用该信息进行api调用,返回的数据将在submitted.html部分内使用。

index.html partial

<form>
    <select ng-model="input.Color" ng-options="product as product.color for product in products"></select>
    <input type="text" ng-model="input.Qty">
    <button ng-click="submit(input)">Submit</button>
</form>

app.js

var myApp = angular.module('myApp', []);

myApp.config(function($routeProvider, $locationProvider) {
    $routeProvider
        .when('/', {
            templateUrl: './partials/index.html',
            controller: 'IndexCtrl'
        })
        .when('/submitted', {
            templateUrl: './partials/submitted.html',
            controller: 'SubmittedCtrl'
        })
        .otherwise({
            template: "404 not found"
        })
});

myApp.controller("IndexCtrl", function($scope, $routeParams) {
    $scope.submit = function(data) {
        $http.jsonp('http://api.remoteserver/' + data.Color.color + '/' + data.Qty + '?callback=JSON_CALLBACK')
                .success(function(result) {
                //how do I get this data loaded into SubmittedCtrl?
        });
    }
});

myApp.controller("SubmittedCtrl", function($scope, $routeParams) {

});

0 个答案:

没有答案