通过Angular.js中的表单提交将参数传递给路由
-
20-12-2019 - |
题
我正在尝试根据某些参数实现搜索。我有视图/家庭,这包括一个表格。我不会通过客户ID重定向到/编辑客户:/ customerid视图。
html ,
<form>
From: <input type="text" name="customernumber"><br>
<a href="#/edit-customer/3">asdasd</a>
</form>
.
路由,
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: '/'
});
}]);
.
如何实现这一目标?
解决方案
这就是我理解的是您正在寻找的,注意输入元素上的NG-Model指令
<form>
From: <input type="text" ng-model="customerId" name="customernumber"><br>
<a href="#/edit-customer/{{customerId}}">asdasd</a>
</form>
. 不隶属于 StackOverflow