Promise在AngularJS中被两次调用

时间:2019-03-15 07:39:55

标签: angularjs promise angular-promise angularjs-service

实际上,我的诺言执行始于if,条件是一切正常,但问题是服务调用两次被调用,而函数opmodel.concactDetails被调用两次。

我正在调用concatDetails,一旦返回一个承诺,它将调用getPortfolio哪个服务,但我不明白为什么调用了两次

model.gridevents = function () {                            
    if (!opmodel.filterData.portfolioID) {
        opmodel.concactDetails(true)
        .then(model.setportifolioDetails)
        .then(model.getDrawsDetails);
    }
    gridPagination.setGrid(grid);
    gridTransform.setGridModel(grid);
    gridTransform.setGridPaginationModel(gridPagination);
    gridPagination.setData(gridPaginationConfig);
    return model;
};

model.setportifolioDetails = function (resp) {
    opmodel.setportifolioDetails(resp);
    model.getDrawsDetails();
};

model.getDrawsDetails = function () {
    model.setBusyIndicator(true);
    svc.getDrawsDetails(opmodel.filterData)
        .then(model.bindDraws, model.error);
};
model.concactDetails = function (flag) {
    model.flag = flag;
    var data = {
        data: {
            contact: session.get('contact'),
            portalsettings: session.get('portalsettings'),
            companyName: session.get('companyName'),
            epayEnabled: session.get('epayEnabled'),
            prodName: session.get('prodName'),
            showProductName: session.get('showProductName'),
            userRole: session.get('userRole'),
            statementPeriodCustom: session.get('statement_period_custom'),
        }
    };
    return model.updateFilterDetails(data);
};
model.updateFilterDetails = function (resp) {
    model.filterData = {
        setDefault: true,
        startDate: moment(resp.data.contact.portalDefaultStartDate).format("MM/DD/YYYY"),
        endDate: moment(resp.data.contact.portalDefaultEndDate).format("MM/DD/YYYY"),
        filterStartDate: moment(resp.data.contact.portalDefaultStartDate).format("YYYY-MM-DD"),
        filterEndDate: moment(resp.data.contact.portalDefaultEndDate).format("YYYY-MM-DD"),
        includeUnpaid: false,
        dateRangeFunction: resp.data.contact.portalDefaultFilterPeriod ?
            (resp.data.contact.portalDefaultFilterPeriod === "customPeriod()" && resp.data.contact.customPeriodLabel === "None") ?
            "thisMonth()" : resp.data.contact.portalDefaultFilterPeriod : 'thisMonth()',
        customPeriodLabel: resp.data.contact.customPeriodLabel,
        portfolioID: resp.data.contact.portalDefaultPortfolioID,
        portfolioId: resp.data.contact.portalDefaultPortfolioID,
        epayInfo: resp.data.contact.epayInfo,
        epayEnabled: resp.data.epayEnabled,
        allowOwnerChangeBankInfo: resp.data.portalsettings.allowOwnerChangeBankInfo,
        showRealTimeData: resp.data.portalsettings.showRealTimeData,
        statementPeriodCustom: resp.data.statementPeriodCustom,
    };
    model.contactDetails = resp.data;
    if (!model.flag) {
        if (resp.data.portalsettings.showRealTimeBalances !== undefined && resp.data.portalsettings.showRealTimeBalances !== true) {
            state.go("ownerPortal.alternateDashboard");
        }
    }
    model.flag = undefined;
    return model.portfolioData();
};
model.setportifolioDetails = function (resp) {
     if (resp.data.length > 0) {
        model.portfolios = resp.data;
        model.filterData.portfolioID = model.filterData.portfolioID ?
            model.filterData.portfolioID : resp.data[0].id;
        model.filterData.portfolioId = model.filterData.portfolioID;
        model.portfolioName = _.find(resp.data, {
            id: model.filterData.portfolioId
        }).name;
     }
};

0 个答案:

没有答案