配列はjoinedArray
です。あるケースでは、値は[undefined, undefined]
です。配列がAngular jsで未定義のオブジェクトで構成されている場合、 `if`条件を真理としてアサートする方法
私が書かれているようなものif condition
:
if(joinArray === undefined){
vm.selectedFriends = [];
angular.forEach($scope.contacts, function(contact){
if (contact.selected)
vm.selectedFriends.push(contact.email);
});
$http({
url: 'http://192.168.2.8:7200/api/creatList',
method: 'POST',
data: {wData:userData, uId:vm.uid, userName:vm.uName, email:vm.selectedFriends}
}).success(function(res) {
console.log("success");
}, function(error) {
console.log(error);
alert('here');
});
$mdDialog.hide(userData);
} else {
$http({
url: 'http://192.168.2.8:7200/api/sendMail',
method: 'POST',
data: {wData:userData, email:joinArray, uId:vm.uid, userName:vm.uName}
}).success(function(res) {
console.log("success");
}, function(error) {
console.log(error);
alert('here');
});
$mdDialog.hide(userData);
}
時には[value, undefined]
または[undefined, value]
ようjoinedArray
戻ります。しかし、両方の値が定義されていない場合にのみ、if
の条件に渡されます。そうでない場合は、else
の条件になります。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every – Bergi
[配列が空であるかどうかを確認する](http://stackoverflow.com/)が重複している可能性があります。質問/ 11743392 /配列が空であるかどうかチェックする) –