搜索输入和 $state.go [英] Search input and $state.go

查看:28
本文介绍了搜索输入和 $state.go的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 AngularJS 和 Elasticsearch 构建了一个小型电影搜索应用.
我使用 AngularJS UI Bootstrap Typeahead 进行自动完成.

I've built a small movie search app using AngularJS and Elasticsearch.
I used AngularJS UI Bootstrap Typeahead for autocomplete.

我的应用程序非常简单,hp,结果页面,联系表.
我想做的是使用 ngKeydown/ngKeypress$state.go 在搜索输入上.
我正在寻找的是,当用户开始在搜索输入中的 hp 上键入他们的查询时,页面会在第一次按键时转到结果页面,然后开始出现建议.

My app is pretty simple, hp, results page, contact form.
What I'd like to do is use ngKeydown/ngKeypress and $state.go on the search input.
What I'm looking for is when a user starts typing their query on the hp in the search input, the page goes to the results page on the first keypress and then suggestions begin to appear.

像这样:

<form>
  <input type="text ng-keypress="$state.go('results')">
</form>

推荐答案

控制器的依赖项在 html 中并不是神奇地可用.您需要在控制器上创建该函数,并从您的 html 中调用该函数.

The dependencies of your controller aren't magically available in your html. You need to create the function on the controller, and call that function from your html.

控制器:

function myController($scope, $state) {
    $scope.navigate = function (destination) {
        $state.go(destination);
    }
}

html:

<form>
    <input type="text ng-keypress="navigate('results')">
</form>

这篇关于搜索输入和 $state.go的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆