I'm struggling a bit with my web application
First time working with JSON for me.
Where the json looks like this
{
"Code":"310254351",
"FirstName":null,
"LastName":null,
"NewUser":true
}
I can see in my HTML that the 'NewUser' bool comes through perfectly. Somehow I cannot get is to work in JS (angular)
$scope.checkForUserProfile = function () {
$scope.getUserProfile();
if ($scope.userprofile.NewUser)
{
$scope.showWelcome = false;
$scope.showProfileNew = true;
}
else (!$scope.userprofile.NewUser)
{
$scope.showWelcome = true;
}
}
$scope.getUserProfile = function () {
$scope.loading = true;
$http.post('http://localhost:49165/Service1.svc/userprofile/get/').then(
function (response) {
$scope.userprofile = response.data;
}, function (errResponse) {
console.error('Error while getting user profile');
});
$scope.loading = false;
};
Am I missing some casting or something?
I tried several ways also this doesn't seem to work;
if ($scope.userprofile.NewUser = true){
// do something }
$scope.userprofile
it seems undefined. Should you want to do this:
$scope.userprofile = $scope.getUserProfile();
else (!$scope.userprofile.NewUser)
else
doesn't take a boolean like that! Remove the bit between ()
.
So the if
becomes:
if ($scope.userprofile.NewUser)
{
$scope.showWelcome = false;
$scope.showProfileNew = true;
}
else
{
$scope.showWelcome = true;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.