我有一个简单的表格,你选择一种颜色并输入数量。当您单击“提交”按钮时,我想将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) {
});