2016-03-27 14 views
2

Hala angularJs ile yeni bir sayfa html başka bir sayfaya (aslında bir model) bir değişkenin değerini geçirmeye çalışıyorum. Sayfaların her ikisi de aynı denetleyiciyi paylaşır.

<button type="submit" class="btn btn-primary pull-right" 
         data-ng-click="ctrl.nextOperation(chosenProducts,'lg')">Next</button> 
       </div> 

app.js:

self.nextOperation = function(chosenProducts,size) 
{ 
    $scope.chosenProducts= chosenProducts; 
    $scope.product = chosenProducts[0]; 
    console.log($scope.product.nameProduct); 
    console.log("test test nextt Operation "+chosenProducts[0].nameProduct);  
    var modalInstance = $uibModal.open({ 
     animation : $scope.animationsEnabled, 
     templateUrl : 'partials/operation.html', 
     controller : 'ProductsController', 
     scope : $scope, 
     size : size, 
     resolve : { 
         } 
    }); 

}; 

Sayfa 2:

Html Page1 pb lütfen teşhis etmek bana yardım eder İşte

<table> 
      <tbody> 

       <tr class="cake-bottom" > 
       <td class="cakes">     
        <div class="product-img2"> 
        </div> 
       </td> 
       <td class="cake-text"> 
        <div class="product-text"> 
         <h3>{{product.nameProduct}}</h3> 
         <p>Product Code: {{product.numSerie}}</p> 
        </div> 
       </td> 
       <td class="quantity">     
        <div class="product-right"> 
        <input min="1" type="number" id="quantity" name="quantity" value="" class="form-control input-small">     
        </div> 
       </td> 
       <td> 
        <h4>{{product.price}}</h4> 
       </td> 
       <td class="btm-remove"> 
       <div class="close-btm"> 
        <h5>Remove</h5> 
       </div> 
       </td> 


       </tr> 
      </tbody> 
     </table> 
+0

Bu http://stackoverflow.com/a/33164461/178163 adresine bakın. Bunu deneyin, örneğin: {{$ parent.product. price}} –

+0

$ $ yoluyla erişmek büyük değildir. Her zaman kötü olan yüksek derecede birleştirilmiş bir uygulama yapıyorsunuz. –

cevap

1

bir tam örnektir Bootstrap modal ve üst değişkenleri ana denetleyiciye geçirme. Plunker Here

index.html

<!DOCTYPE html> 
<html> 

    <head> 
    <link data-require="[email protected]" data-semver="3.3.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" /> 
    <script data-require="angula[email protected]" data-semver="1.5.0" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.js"></script> 
    <script data-require="[email protected]" data-semver="1.1.2" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.1.2/ui-bootstrap-tpls.js"></script> 
    <link rel="stylesheet" href="style.css" /> 
    <script src="script.js"></script> 
    </head> 

    <body ng-app="my-app"> 
    <div ng-controller="myController as mc"> 
     <h1>Hello Plunker!</h1> 
     <br><br> 
     myObject = {{mc.myObject}} 
     <a ng-click="mc.openModal(mc.myObject)">Open Modal</a> 
    </div> 
    </body> 

</html> 

myModalContent.html

<h2>I am a modal</h2> 
{{modal.myObject}} 

script.js

var myApp = angular.module('my-app', ['ui.bootstrap']); 

myApp.controller('myController', function($uibModal) { 
    var self = this; 
    self.myObject = {id: 1, value: "Hello"}; 
    self.openModal = function (size) { 
    var modalInstance = $uibModal.open({ 
     templateUrl: 'myModalContent.html', 
     controller: 'ModalInstanceCtrl as modal', 
     size: size, 
     resolve: { 
     // Any properties here become injected as arguments on the modal controller. 
     items: function() { 
      return self.myObject; 
     } 
     } 
    }); 
    }; 
}); 

// items is injected from the resolve property of the parent controller instantiating the modal. 
myApp.controller('ModalInstanceCtrl', function(items) { 
    var self = this; 
    self.myObject = items; 
}); 
+0

Cevabınız için teşekkür ederiz. Acualy ben kontrolör adını sildim ve benim gidermek kararında birlikte eklendi: { \t \t \t \t chosenProducts: function() { \t \t \t \t dönüş chosenProducts; \t \t \t \t \t} Fakat hala sayfa 2 – yeddez

+0

k değerlerindeki değerler yok. Bir plunker oluştur ve yardımcı olabilirim. –

+0

İşte burada: https://plnkr.co/edit/EzVVe3Mzt4HTSPEcrH4k?p=preview – yeddez

2

Açılırken açılır pencerenin modal yoksayısı için yeni denetleyici örneği oluştururken, controlleroption10 seçeneklerinden controller seçeneklerini kaldırın.

var modalInstance = $uibModal.open({ 
    animation : $scope.animationsEnabled, 
    templateUrl : 'partials/operation.html', 
    //controller : 'ProductsController', //<-- remove controller name 
    scope : $scope, 
    size : size 
}); 
0

Yardımlarınız için teşekkürler! Sorunu çözebilirim, denetleyiciyi tanımlamam gerekiyordu benim modal