2016-09-22 132 views
0

我使用http攔截器來處理錯誤。是否有可能使用MD對話框彈出一個窗口,顯示錯誤消息,一旦捕獲到某些錯誤。將$mdDialog注入服務時發生circular dependency錯誤。我應該在哪裏綁定errorMsg如果$mdDialog可以用於此服務?

攔截:

.factory('httpInterceptor', ['$q', '$mdDialog', function($q, $mdDialog){ 
    return { 
     'response': function(res) { 
      var status = res.data.status; 
      var errorMsg = res.data.payload.message; 
      if(status === 'fail') { 
       $mdDialog.show({ 
       // controller: ???, 
       // scope: ???, 
       templateUrl: 'error.html', 
       }) 
       return $q.reject(res); 
      } 
      return res; 
     } 
    } 
}]) 

回答

2

是的,你可以使用控制器顯示$範圍變量和解決,

$mdDialog.show({ 
     controller: function($scope, $mdDialog){ 
     // do something with dialog scope 
     }, 
     template: '<md-dialog aria-label="My Dialog">'+ 
        '<md-dialog-content class="sticky-container">{{test}}' + 
        '</md-dialog-content>' + 
        '<md-button ng-click=close()>Close</md-button>' + 
        '</md-dialog>', 
     controller: 'modalCtrl', 
     resolve: { 
     test: function() { 
      return 'test variable'; 
     } 
     } 
    }); 

控制器:

app.controller('modalCtrl', function($scope, $mdDialog, test) { 
    $scope.test = test; 
}); 

DEMO

+0

我認爲他的問題是,如果他可以在角度爲 –

+0

的配置路徑上聲明的httpInterceptor中使用它,你已在'$ mdDialog.show()中有兩次'controller'' – Phil

+0

是@PauloGaldoSandoval – vincentf

相關問題