2016-08-14 5 views
0

私の角型アプリケーションには、モーダルモードとモーダルモードの両方で使用できるコントローラがあります。私はどのモードであるかをチェックしたいと思います。誰か助けてくれますか?Angularjs - コントローラモーダルモードのチェック

注文コントローラ

$scope.chooseClient = function() { 
     $uibModal.open({ 
      templateUrl: 'partials/client/edit.html', 
      controller: 'ClientEditController', 
     }).result.then(function (client) { 
      // Modal OK 
      if (client) { 
       $scope.model.client = client; 
      }  
     }, function (status) { 
      // Modal cancelado 
     }); 
    }; 

クライアントコントローラ

.controller('ClientEditController', 
    function ($scope, $location) { 

     $scope.cancel = function() { 
      if (//I would check if modal mode) { 
       $scope.$dismiss('cancel'); 
      } else { 
       $location.path("/client/list"); 
      }  
     }; 



}); 
+0

私は簡単な方法があるかどうかわからないが、[このドキュメント]によると(https://github.com/angular-ui/bootstrap/tree/master/src/modal/docs)、あなたの要素に 'openedClass'が適用されているかどうかを少なくとも確認できます。 –

答えて

0

あなたはフラグ付きresolveオブジェクトを渡すことができます。そうすれば、コントローラのルートで同じ解決策をパスし、コントローラに解決するために注入する必要があります。

$scope.chooseClient = function() { 
    $uibModal.open({ 
     templateUrl: 'partials/client/edit.html', 
     controller: 'ClientEditController', 
     resolve: { 
      isModal: true 
     } 
    }).result.then(function (client) { 
     // Modal OK 
     if (client) { 
      $scope.model.client = client; 
     }  
    }, function (status) { 
     // Modal cancelado 
    }); 
}; 

とチェックより:

.controller('ClientEditController', function ($scope, $location, isModal) { 
    $scope.cancel = function() { 
     if (isModal) { 
      $scope.$dismiss('cancel'); 
     } else { 
      $location.path("/client/list"); 
     }  
    }; 
}); 

参照ドキュメント:$uibModal

+0

ありがとう、ロン・ダドン。出来た! – araraujo

関連する問題