Returning a JSON object back from VM to page typescript


Hey guys I’m trying to return a JSON object that gets called from an API in my view-model


constructor() {
    requestor.get(url).then((res) => {
        responseObj = res;
        let users = responseObj.Users;
        if (!Users) {
            return false;
        } else {
            // console.log(JSON.stringify(users));
            return users;


liveUserDataObjs = new UserViewModel;

my-page.ts returns


Any idea why my json object is not getting passed to my-page.ts?

Any help will be apprecited.


At first look, it must return false every time :wink:

See first if clause

  1. You don’t construct UserViewModel, there are no method call () brackets.
  2. You are making asynchonous calls in the constructor, it is not guaranteed that at the time of assignment you will have the users value.
  3. you check for Users while your variable is users
  4. You are attempting to return a value (users) in the constructor of an object… This appears wrong on a number of levels. Why not assign the value to a property?