passing a parameter to a route from via a form submission in angular.js
-
20-12-2019 - |
Question
i'm trying to implement a search based on certain parameters. i have the view /home and that consists a form. I won't it to redirect to /edit-customer:/customerId view with customer id.
HTML,
<form>
From: <input type="text" name="customernumber"><br>
<a href="#/edit-customer/3">asdasd</a>
</form>
route,
app.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/', {
title: 'Customers',
templateUrl: 'partials/customers.html',
controller: 'listCtrl'
})
.when('/edit-customer/:customerID', {
title: 'Edit Customers',
templateUrl: 'partials/edit-customer.html',
controller: 'editCtrl',
resolve: {
customer: function(services, $route){
var customerID = $route.current.params.customerID;
return services.getCustomer(customerID);
}
}
}).when('/home',{
title: 'home',
templateUrl:'partials/home.html',
}).when('/results',{
title: 'search results',
templateUrl: 'partials/results.html',
})
.otherwise({
redirectTo: '/'
});
}]);
how can i achieve this?
Solution
This is what I understand you are looking for, note ng-model directive on input element
<form>
From: <input type="text" ng-model="customerId" name="customernumber"><br>
<a href="#/edit-customer/{{customerId}}">asdasd</a>
</form>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow