javascript - How to use $state.go on ng-submit -
i have search form on results page small search app built using angularjs , elasticsearch. started using ui-router ngroute , need figure out how use $state.go() on ng-submit button search form return results on results page.
ui router config
$stateprovider .state('search', { url: '/', views: { '': {templateurl: 'templates/search.html'},//parent view 'navbar@search': {templateurl: 'templates/navbar.html', controller: 'typeaheadctrl'}, 'searchdisplay@search': {templateurl: 'templates/results.html', controller: 'typeaheadctrl'}, 'pagination@search': {templateurl: 'templates/pagination.html', controller: 'typeaheadctrl'} } })
search form
<form ng-submit="search()" class="navbar-form" id="global-search" role="search"> <div class="input-group"> <input type="text" name="q" ng-model="searchterms" class="form-control input-md" placeholder="search" id="search-input" uib-typeahead="query query in getsuggestions($viewvalue)" typeahead-on-select="search($item)" autofocus> <div class="input-group-btn"> <button class="btn btn-primary" type="submit"><i class="fa fa-search"></i></button> </div> </div> </form>
my ng-submit calls search() looks after added $state.go()
$scope.search = function() { resetresults(); $scope.filters.selectedfilters = []; var searchterms = $scope.searchterms; if (searchterms) { $scope.results.searchterms = searchterms; } else { return; } $state.go('/search', {term: $scope.searchterms}); getresults();//uses service results data search server
};
this results in error: error: not resolve '/search' state 'search' @ object.y.transitionto
have no idea that, still getting head around ui-router. trying figure out best method use ng-submit send search query. suggestions?
you shall write state name in state.go
instead of url:
$state.go('search', {term: $scope.searchterms});
and add query parameters expect:
$stateprovider .state('search', { url: '/?term', ...
Comments
Post a Comment