console.log Angular指令范围输出“[object Object] No Properties”

时间:2013-05-30 16:37:17

标签: angularjs angularjs-directive

查看http://egghead.io处的视频,我看到作者使用console.log来注销$ scope或scope对象的内容。 Chrome中的输出是可钻取的对象。但是,当我这样做时,Chrome提供的输出是:

    [object Object]
No Properties

使用console.dir具有相同的效果。有什么建议吗?

谢谢,

2 个答案:

答案 0 :(得分:56)

+运算符调用将返回'[object object]'

的对象的toString方法

所以使用这样的日志:

console.log('scope is ' + scope);

生成的字符串范围是[object object]

而是使用带逗号的console.log()方法(如下所述)能够深入到范围对象中:

console.log('scope is', scope)

答案 1 :(得分:2)

使用 console.log(formValues);  而不是 console.log(" Values =" + formValues); 。 如果您使用 console.log(" Values =" + formValues); ,则将其视为字符串并输出为[Object object]

相关问题