我在将查询参数与 UI Router 用于小型搜索应用时遇到问题。
在我更好地理解 Angular 之前,它现在真的很简单,只是一个主页和结果页面。主页上只有一个具有自动完成功能的搜索框。搜索页面有相同的搜索框和结果。在我的搜索框中,我在调用 search() 的按钮上有 ng-submit。在 search() 中,我有 $state.go('state', {q: 'searchTerms'}),searchTerms 是我输入的 ng-model。
从主页转到结果页,url 保持不变:
http://localhost:8000/app/search?q=searchTerms
而不是 http://localhost:8000/app/search?q=usertypedinput
为什么?
我的州(路线)
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'home/home.html', controller: 'homeCtrl'})
.state('search', {
url: '/search?q',
views: {
'' : { templateUrl: 'search/search.html', controller: 'searchCtrl' }
//add more views here when necessary
}
});
如您所见,我使用命名 View 而不是嵌套 View 。很多示例都使用嵌套 View ,所以我很想知道这是否导致了问题,或者我是否遗漏了某些内容?
在搜索应用中使用嵌套 View 会更好吗?
最佳答案
我发现了,除了 state.go 中一些令人讨厌的语法之外,一切都是正确的:((
$state.go('search', {q: 'searchTerms'});
应该是
$state.go('search', {q: $scope.searchTerms});
不带单引号的搜索术语 AND $scope
其他人不会在如此简单的事情上浪费时间。
关于javascript - 具有命名 View 的 UI 路由器查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36457544/