angularjs - Javascript null checking not working as expected -
i'm using angularjs framework , connect webservice fetch json data. have following code:
$login.onlinelogin($scope.credentials). success(function (data, status, headers, config) { if (data !== null ) { console.log('successful login!'); console.log('returned data: ' + data); } else { console.log('failed login...'); } }). error(function (data, status, headers, config) { console.log('http error...'); });
now, when http call comes status still 200:ok object returns null, in case user provided wrong user credentials example. i'm expecting happen in case if object not null, it'll print out 'successful login!' , print out object.
however, what's happening use fake credentials, webservice returns null. still 'successful login!' gets printed, , after prints 'returned data: null'... doesn't make sense. if data null, should never have ended in code block?
if you're not sure type of variable use.
console.log(typeof variablename)
in case, problem can fixed using
if (data != 'null') { ...
Comments
Post a Comment