我不断收到错误
Error: undefined is not an object (evaluating '$rootScope.user.userMessage')
使用此代码:
if (typeof($rootScope.user.userMessage) === null) {
但如果我在 $rootScope.user.userMessage 中有一些东西,它就不会崩溃。我如何执行检查以查看它是否未定义或为空,以便事情不会中断?
我尝试过的其他事情包括:
if (typeof($rootScope.user.userMessage) === undefined) {
if ($rootScope.user.userMessage === undefined) {
最佳答案
if($rootScope.user && $rootScope.user.userMessage){
...
}
关于javascript - 未定义不是对象 - Angular $rootScope.user.userMessage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33822570/