tv3free
tv3free

Reputation: 183

Force boolean result from promise function in angularjs

In angularjs, I am trying to return get isInternal true or false value based on a promise function. But I am getting another promise (Promise {$$state: Object} $$state : Object status : 1 value : true)

$scope.isInternal = userInfo.getUser().then(function(user) {return user.internal;});
          console.log($scope.isInternal);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>

Upvotes: 0

Views: 393

Answers (2)

JavaHead
JavaHead

Reputation: 663

here is a good tutorial on promises , three is a section there that specificly says why something like this :

var var = service.getAsyncData() ... won't work as expected

tutorial on promises

Upvotes: 0

Jordi Ruiz
Jordi Ruiz

Reputation: 487

You should try:

userInfo.getUser().then(function(user) {
  $scope.isInternal = user.internal;
});

Upvotes: 3

Related Questions