2014-04-04 79 views
0

做我有角回調函數時,函數的角度

$rootScope.openMobileUpdateModal = function() { 
    ......something....... 
     var modalInstance = $modal.open({ 
     templateUrl: 'mobileModal.html', 
     controller: ModalInstanceCtrl 
     }); 
    }; 

這個功能,我需要的功能(模式打開時並創建元素)當此功能完成後,將被調用。如何在這個函數上創建回調?

回答

0

您應該通過opened參數來打開方法。當模式窗口打開時,opened是一個承諾,將被解決。

$rootScope.openMobileUpdateModal = function() { 
    ......something....... 
    var modalInstance = $modal.open({ 
    templateUrl: 'mobileModal.html', 
    controller: ModalInstanceCtrl, 
    opened: // Your Promise object here 
    }); 
}; 
+0

什麼是承諾對象? –

+0

@ user3433459請查看AngularJS文檔http://docs.angularjs.org/api/ng/service/$q http://www.promisejs.org/ –

0

你只需要一個函數傳遞給打開promisse ...

$rootScope.openMobileUpdateModal = function() { 
    ......something....... 
    var modalInstance = $modal.open({ 
    templateUrl: 'mobileModal.html', 
    controller: ModalInstanceCtrl 
    }); 

    modalInstance.opened.then(function() { 
// The modal is opened and the elements are created 
    }); 

};