Create promise in AngularJS

a 夏天 提交于 2019-12-01 20:37:15

You shouldn't need to wrap everything in the $q() call. In order to promisify navigationMap use $q.when:

function returnMapAsync() {

    if (navigationMap) {
        return $q.when(navigationMap);
    }
    return ServerRequest.getNavigationMap();
}

You don't need to wrap it into one more promise since ServerRequest.getNavigationMap() is a promise:

function returnMapAsync() {

    if (navigationMap) {
        return $q.resolve(navigationMap);
    } 

    return ServerRequest.getNavigationMap().then(function(data) {
        navigationMap = data.object;
        return navigationMap;
    });
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!