0

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

index.html 部分

<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>

应用程序.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) {

});
4

0 回答 0