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

查看:63
本文介绍了搜索输入和$ 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天全站免登陆