console.log没有显示正确的值 [英] console.log is not showing correct values

查看:27
本文介绍了console.log没有显示正确的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安慰一个对象,尽管它没有引发任何错误,但是一段时间后会显示我想要的结果,而我却无法检索它.

I am trying to console an object although it's not throwing any error but the result i want is shown after some time and I am not able to retrieve it.

它显示一个i图标,上面写着下面的值刚刚被评估",我无法获取该值.

It shows an i icon which says 'value below was evaluated just now' and I am not able to get that values .

OUTPUT: Promise {$$state: {…}}
        $$state:
        status:1
        value:"Modifier"
        __proto__:Object
        __proto__:Object

我需要一个变量中的值:"MODIFIER".如何获得它.预先感谢.

And I need that value:"MODIFIER" in a variable. How to get it. Thanks in advance.

console.log($ translate('MODIFY'));我在控制器内部使用angular-translate.

console.log($translate('MODIFY')); I am using angular-translate inside a controller.

当我使用console.log($ translate('MODIFY')['$$ state'].value)时,由于下面的值刚刚被评估",它显示为undefined.我需要稍后的值或任何获取它们之前的方法.

When I use console.log($translate('MODIFY')['$$state'].value) it shows undefined just because of the reason "value below was evaluated just now". I need the later values or any way to get them before.

推荐答案

此处提供的是一个承诺,该承诺将异步返回您的值(即从执行流程中返回).正确的处理方法如下:

What you have here is a promise, which will return you values asynchronously(i.e out of the flow of execution). The correct way to handle this is as follows:

promiseObj.then(function(value){//您在这里编码})

当我凝视它的时候,这里帮助我理解了诺言.

When i was staring out this here helped me understand promises.

http://andyshora.com/promises-angularjs-explained-as-cartoon.html

希望这会有所帮助,干杯!

Hope this helps, Cheers!

这篇关于console.log没有显示正确的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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