1

I have the following code and I am trying to use the return value of a function to initialize a property of an object.

$scope.data = {
  trackingItemStatus: {
    options: SPListUtility.GetChoiceOptionsJson(),
    defaultOption: {value: 'Active', text: 'Active'}
  }
}

Right before returning from my service above I log the variable to be returned and it is coming back as follows so I know it should be working:

[{"text":"Active","value":"Active"},{"text":"Closed","value":"Active"},{"text":"On-Hold","value":"On-Hold"},{"text":"Resolved","value":"Resolved"}]

I feel like this should be simple. I just want to assign the return value of my function to data.item.options but it won't work just keeps coming back empty. Am I missing something obvious here?

3
  • 3
    Post the real code. What you're doing should work, unless you're doing something wrong. We can't tell however unless the real code is posted. Also, if you're getting errors in the console, that would be extremely useful too. Commented Jun 7, 2016 at 19:38
  • Maybe someFuncThatReturnsArray() returns a Promise, and you are testing it for the resolved value? Commented Jun 7, 2016 at 19:43
  • That was the problem, it was returning a promise, thanks! Commented Jun 7, 2016 at 19:52

1 Answer 1

3

It's likely that the call to SPListUtility.GetChoiceOptionsJson() returns a promise, in which case you must resolve the returned value, like so:

SPListUtility.GetChoiceOptionsJson().then(function (value) {
  $scope.data = {
    trackingItemStatus: {
      options: value,
      defaultOption: {value: 'Active', text: 'Active'}
    }
  };
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.