2016-05-24 12 views
0

モーダルから別のページにデータを渡す必要があります。あなたはこの仕事を達成するために私を助けてくれますか?モーダルから別のページにデータを渡す

$scope.productdetails = function (size,selectedproduct) 
    {  
    var modalInstance = $uibModal.open({   
    templateUrl: 'ProductDetails.html',    
    controller: function ($scope, $uibModalInstance, product) { 
     $scope.product = product; 

     $scope.buynow = function (path) { 
      $uibModalInstance.close($scope.product); 
      $location.path(path); // Need to pass $scope.product to the new page 
     }; 

     $scope.cancel = function() { 
      $uibModalInstance.dismiss('cancel'); 
     }; 
    }, 
    size: size, 
    resolve: { 
     product: function() { 
      return selectedproduct; 
     } 
    } 
});   
+0

ブライアン・ハンは、私はほぼ全面的に自分自身を使用して自分のサイト上での一つの方法、概説アプリ – charlietfl

+0

の異なる部分間のDTAを共有するためのサービスを使用します。http://brianhann.com/pass-data-to-a-をui-bootstrap-modal-without-scope。 – Brian

答えて

1

$uibModal上のドキュメントを必ずお読みください:https://github.com/angular-ui/bootstrap/tree/master/src/modal/docs

open()方法は、その中にいくつかの有用なものを持つオブジェクトを返します。現在、あなたはそのオブジェクトで何もしていませんが、それが魔法の場所です。

は、このような modalInstance.result約束使い、モーダルを開いているコントローラにデータを渡すには:

modalInstance.result.then(function(data) { /*... do something with the data*/ }); 

それを設定した後に、あなたは$close()関数を使用することができる範囲でこのモーダルライブラリの場所へresult約束を解決してください。

var data = {info: 'information to be returned to the parent controller'}; 
$scope.$close(data); 
+0

私は次のように書いています。 modalInstance.result.then(function(product){ $ scope.selectedProduct = product; $ location.path( 'cart'); }); 製品を新しい場所のパスにどのように渡す必要がありますか? – Rubel

+1

ショッピングカートを実装しているので、ユーザーの選択内容をクッキーに保存してから、そのカートを「カート」ページで取得する必要があります。 Cookieは、ほぼすべてのEコマースWebサイトでその目的で使用されています。 – HankScorpio

関連する問題