문제

i ng-repeat가 있고 동일한 범위 변수를 모달 창에 전달하는 모달을 추가하려고합니다.나는 모달 창을 열 수 있지만 NG-Repeat의 범위 값은 모달 내부에 표시되지 않습니다.바라건대 내 코드가 더 잘 설명됩니다.이것은 내가 지금까지 가지고있는 것입니다 :

        <div ng-controller="CustomerController">  
        <div ng-repeat="customer in customers">
               <button class="btn btn-default" ng-click="open()">{{ customer.name }}</button>

                <!--MODAL WINDOW--> 
                <script type="text/ng-template" id="myModalContent.html">
                    <div class="modal-header">
                        <h3>The Customer Name is: {{ customer.name }}</h3>
                    </div>
                    <div class="modal-body">
                            This is where the Customer Details Goes<br />
                            {{ customer.details }}
                    </div>
                    <div class="modal-footer">

                    </div>
                </script>

        </div>  
        </div>
.

컨트롤러 :

   app.controller('CustomerController', function($scope, $timeout, $modal, $log, customerServices) {
    $scope.customers= customerServices.getCustomers();

    // MODAL WINDOW
    $scope.open = function () {

        var modalInstance = $modal.open({
          templateUrl: 'myModalContent.html',
             });

    };

});
.

위의 모달 창이 열립니다.그러나 NG- 반복에서 {{Customer.Name}}와 같은 고객 세부 정보가 모달 창에 전달되지 않습니다.컨트롤러에 뭔가 잘못 되었습니까?

"noreferrer"> http : // angular-ui.github.io/bootstrap/

편집 :

여기서는 JSFiddle 샘플입니다. http://jsfiddle.net/ALIEN_TIME / 8S9SS / 3 /

도움이 되었습니까?

해결책

바이올린 및 아래 코드를 업데이트했습니다.나는 도움이 될 것이기를 바랍니다.

에 관해서는
var app = angular.module('app', ['ui.bootstrap']);

app.controller('ModalInstanceCtrl', function ($scope, $modalInstance, customer)
{
$scope.customer = customer;

});

app.controller('CustomerController', function($scope, $timeout, $modal, $log) {

    $scope.customers = [
        {
        name: 'Ricky',
        details: 'Some Details for Ricky',
        },
        {
        name: 'Dicky',
        details: 'Some Dicky Details',
        },
        {
        name: 'Nicky',
        details: 'Some Nicky Details',
        }
    ];

    // MODAL WINDOW
    $scope.open = function (_customer) {

        var modalInstance = $modal.open({
          controller: "ModalInstanceCtrl",
          templateUrl: 'myModalContent.html',
            resolve: {
                customer: function()
                {
                    return _customer;
                }
            }
             });

    };

});
.

다른 팁

이는 내가 반복하고 편집하고자하는 항목을 처리하는 것에 대해 내 모달을 설정하는 방법입니다.다른 컨트롤러로 작동하도록 설정을 제안합니다. 왜냐하면 DI를 사용하여 해결 된 항목을 자식 범위에 주입 할 수 있습니다.

$scope.openModal = function(item) 
    // This sets up some of the options I want the modal to open with
    var options = {}
    angular.extend(options, {
      templateUrl: '/views/userItems/form.html',
      controller: 'ItemEditController',
      resolve: {
        // I resolve a copy of the so it dont mess up the original if they cancel
        item: function() { return angular.copy(item); }
      }
    });
    $modal.open(options).result.then(function(updatedItem) {
      // after the user saves the edits to the item it gets passed back in the then function
      if(updatedItem) {
        // this is a service i have to deal with talking to my db
        modelService.editItem(updatedItem).then(function(result) {
          // get the result back, error check then update the scope
          if(result.reason) {
            $scope.addAlert({type: 'error', title: 'Application Error', msg: result.reason});
          } else {
            angular.extend(vital, result);
            $scope.addAlert({type: 'success', msg: 'Successfully updated Item!'}); 
          }
        });
      }
    });
  };
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top