我正在尝试根据某些参数实现搜索。我有/home View ,它包含一个表单。我不会将其重定向到带有客户 ID 的/edit-customer:/customerId View 。
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>
关于javascript - 通过 angular.js 中的表单提交将参数传递给路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25003772/