2016-05-17 5 views
0

Ich bin neu in AngularJS. Wie zeigt man Daten im Pop-up nach ausgewähltem Index an?Wie zeigt man Daten im modalen Popup nach ausgewähltem Index (AngularJS)

Hier ist mein Code:

<div class="modal fade" id="myModal" role="dialog"> 
<div class="modal-dialog" > 
    <div class="modal-content"> 
    <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal">&times;</button> 
     <h4 class="modal-title">Modal Header</h4> 
    </div> 
    <div class="modal-body" ng-repeat="product in filtered | limitTo : 1"> 
     <p>{{product.prod_name}} </p> 
    </div> 
    <div class="modal-footer"> 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
    </div> 
    </div> 
</div> 
</div> 

My Button:

<td><button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Detail</button> </td> 

Antwort

0

Lassen Sie mich gehen davon aus, dass die Detail-Taste vorhanden ist gegen alle Produktreihen im Raster. Dann können Sie diese Idee folgen:

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" ng-click ="setValuesForPopup(prod)"> 

Dann in Ihrem Controller:

$scope.setValuesForPopup = function (prod){ 
$scope.product = {}; 
$scope.product.prod_name= prod.prod_name; 
//or $scope.product = angular.copy(prod); 
} 
0

Sie verwenden normalen Bootstrap für Winkel.

Es ist besser, eckigen ui-bootstrap für eckiges Projekt zu verwenden.

Dies ist Link von ui-Bootstrap: http://angular-ui.github.io/bootstrap/versioned-docs/0.12.0/

Und Blick auf folgende Arbeitsbeispiel der offenen modale mit ui-Bootstrap:

HTML-Code:

<!doctype html> 
<html ng-app="ui.bootstrap.demo"> 
    <head> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script> 
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.js"></script> 
    <script src="example.js"></script> 
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> 
    </head> 
    <body> 

<div ng-controller="ModalDemoCtrl"> 
    <script type="text/ng-template" id="myModalContent.html"> 
     <div class="modal-header"> 
      <h3 class="modal-title">I'm a modal!</h3> 
     </div> 
     <div class="modal-body"> 
      <ul> 
       <li ng-repeat="item in items"> 
        <a ng-click="selected.item = item">{{ item }}</a> 
       </li> 
      </ul> 
      Selected: <b>{{ selected.item }}</b> 
     </div> 
     <div class="modal-footer"> 
      <button class="btn btn-primary" ng-click="ok()">OK</button> 
      <button class="btn btn-warning" ng-click="cancel()">Cancel</button> 
     </div> 
    </script> 

    <button class="btn btn-default" ng-click="open()">Open me!</button> 
    <button class="btn btn-default" ng-click="open('lg')">Large modal</button> 
    <button class="btn btn-default" ng-click="open('sm')">Small modal</button> 
    <div ng-show="selected">Selection from a modal: {{ selected }}</div> 
</div> 
    </body> 
</html> 

example.js Code:

angular.module('ui.bootstrap.demo', ['ui.bootstrap']); 
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function ($scope, $modal, $log) { 

    $scope.items = ['item1', 'item2', 'item3']; 

    $scope.open = function (size) { 

    var modalInstance = $modal.open({ 
     templateUrl: 'myModalContent.html', 
     controller: 'ModalInstanceCtrl', 
     size: size, 
     resolve: { 
     items: function() { 
      return $scope.items; 
     } 
     } 
    }); 

    modalInstance.result.then(function (selectedItem) { 
     $scope.selected = selectedItem; 
    }, function() { 
     $log.info('Modal dismissed at: ' + new Date()); 
    }); 
    }; 
}); 

// Please note that $modalInstance represents a modal window (instance) dependency. 
// It is not the same as the $modal service used above. 

angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function ($scope, $modalInstance, items) { 

    $scope.items = items; 
    $scope.selected = { 
    item: $scope.items[0] 
    }; 

    $scope.ok = function() { 
    $modalInstance.close($scope.selected.item); 
    }; 

    $scope.cancel = function() { 
    $modalInstance.dismiss('cancel'); 
    }; 
}); 
Verwandte Themen