AngularJS检查promise是否为空 [英] AngularJS check if promise is empty or not
本文介绍了AngularJS检查promise是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码用于检查数据库中是否有用户,如果发现在视图上显示了一个用户列表,否则显示了具有用户创建形式的视图,但没有进行检查表达我在做什么错
Hi I have this code for the purpose of checking if there are users in the database, if it finds shows a list of users on a view, otherwise shows a view with form of user creation, but didn't work the check expression what I'm doing wrong
users = Users.query();
users.$promise.then(
function (data) {
if (!data) {
$location.url('/NewUser')
} else {
$location.url('/UsersList')
}
});
推荐答案
如果未找到任何内容,则可能返回一个空数组.尝试检查数据长度.
It is probably returning an empty array in case nothing is found. Try checking the data length.
if (data.length == 0) {
$location.url('/NewUser')
} else {
$location.url('/UsersList')
}
这篇关于AngularJS检查promise是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文