javascript - AngularJS ng-init 指令被分配了函数和 promise

标签 javascript angularjs angularjs-ng-repeat promise

我试图使用地理编码器纬度和经度的 promise 。需要从 ng-init 指令触发。但我无法在函数内使用 Promise。 plunker for example我的 ng-init 看起来像这样:

<div>Address {{ $index + 1 }}: {{ facility.address }}<span  ng-init="distance = maps(facility)" > distance = {{distance}}</span></div>

整个代码都在 ng-repeat 中。由于我的代码位于 ng-repeat 中,我无法使用超时。我认为 ng-init 的 span 被替换为 {}这。您可以在 plunker 中查看。 。我不知道发生了什么。

最佳答案

我看了一下你的plunker,在你的ng-init中,你将变量test分配给函数test1的结果,该函数返回一个Promise 并且您无法直接在 Angular 模板中打印 Promise 对象。

由于 test 是一个 Promise 对象,因此您可以使用 test.then(function (result) {/* ... */}).

关于javascript - AngularJS ng-init 指令被分配了函数和 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35939967/

相关文章:

javascript - 使用 while 循环用数组动态包装索引

javascript - 无法捕获 JSON 对象中的键并将它们映射为 CSV 文件中的第一行

unit-testing - 使用资源服务测试 AngularJS Controller

javascript - 当使用 AngularJS 登录后授权 header 不存在时,Spring Security 不会抛出错误

javascript - 在 HTML 表格中添加行跨度的简单方法

javascript - 测量全局命名空间的污染

javascript - 复选框值未在 ng-if 下应用

AngularJS - ng-repeat 一次显示一项

javascript - 表排序(使用 ng-repeat 并使用 ng-if 删除重复列名)

javascript - 添加额外的 btn-group onclick