Currently utilizing AngularJS version 1.5.6 and looking for guidance on properly passing form data using $location.path.
Below is my code snippet for Page A:
<form>
...
<button type="submit" ng-click="submit(formData)">submit</button>
</form>
JavaScript code:
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
// Home
.when("/", {
templateUrl: "A.html",
controller: "ACtrl"
})
.when("/B/", {
templateUrl: "B.html",
controller: "BCtrl"
})
//fallback url if nothing matches
.otherwise({
redirectTo: '/'
});
}]);
app.controller('ACtrl', function ( $scope, $location, $http) {
$scope.formData = {};
$scope.submit = function() {
$location.path("/B/" + $scope.formData );
};
});
//controller for B page
app.controller('BCtrl', ['$scope', '$routeParams',
function($scope,$routeParams) {
$scope.formData = $routeParams.formData;
}]);
This example may seem straightforward, but I'm struggling to find a solution :(
When clicking submit, nothing happens. If I remove the $scope from $scope.formData, I receive an error stating "Error: formData is not defined."
The values in formData are accessible, as confirmed by testing with console.log($scope.formData).
Here is the link to the Plunker: https://plnkr.co/edit/K5zwcmRRyom5HR4a5Q9o
EDIT
The only remaining issue is how to correctly handle the select object in the foreach loop. Assistance would be greatly appreciated.