Angular 使用服务提前输入

Angular typeahead using service

当我使用一项服务时,returns 承诺,提前输入不起作用...在 this plunk 中可能会看到错误...

使用第一种方法 (getLocation),该示例工作正常...但是,当我尝试使用在 getLocation1 中实现的服务时,returns 一个承诺,它失败了:

TypeError: Cannot read property 'length' of undefined

at ui-bootstrap-tpls-0.12.0.js:3638

好像 $q 服务返回的承诺与 $http 的“then”方法返回的对象不同。

谁能帮帮我?

你忘记了 return 第二个例子中的承诺。

var futureGoogle = GoogleService.getAddresses(val);
futureGoogle.then(
    ....

需要替换为

var futureGoogle = GoogleService.getAddresses(val);
return futureGoogle.then(
    ....

Here 是工作 plunker