kittencup / angular2-ama-cn

angular2 随便问
691 stars 101 forks source link

http请求的数据,赋值给变量后,无法打印属性,提示undefined #142

Closed ghost closed 8 years ago

ghost commented 8 years ago

我使用第三方的restful的库https://github.com/troyanskiy/ng2-resource-rest/

在chrome f12调试,console可以输出服务器返回的数据

也可以打印出返回的整个对象 但无法打印整个对象的某个属性

比如返回的对象我赋值给变量 this.allUsers 我可以打印出整个变量 console.log(this.allUsers ) 它可以在chrome的console里显示出来 但是我打印 console.log(this.allUsers.count ) 它就会说 undefined

而我把 this.allUsers 赋值给全局变量 window.aa=this.allUsers 然后在chrome的console里面 输入aa.count却可以得到它属性的值

有朋友知道为什么吗

ghost commented 8 years ago

搞定了,直接在模板里面调用 allUsers.count 就可以了