0

I am trying to make an edit form pop-up as the show page but I am unable to get the data in popup html. Pop-up Code:

 <script type="text/ng-template" id="myModalContent.html">
  <div class="modal-header">
      <h3 class="modal-title">I am a modal!</h3>
  </div>
  <div class="modal-body">
    <h1>{{ visitor11.first_name }}</h1>       
    <div ng-app="VisitorCenter" ng-controller="visitorsController">
      <div ng-repeat="visitor22 in visitors">
        <p>{{ visitor22.first_name }} {{ visitor22.last_name }}</p>
      </div>
    </div>
  </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>

But this "{{ visitor11.first_name }}" is not working.

Js file:

$scope.open = function (index) {

visitor = $scope.visitors[index]
var modalInstance = $modal.open({
  templateUrl: 'myModalContent.html',
  controller: 'ModalInstanceCtrl',
  // size: size,
  resolve: {
    visitor11: function(){
      alert(visitor.first_name +" "+ visitor.last_name);
      return visitor;
    }
  }
});

return visitor;

};

ModalInstanceCtrl:

 visitorCenter.controller('ModalInstanceCtrl', function ($scope, $modalInstance) {

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

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

How can I get this 'visitor' object in my popup html. Please don't try to make any sense of my code above because it won't make any. i am just doing random stuff for learning angularJs. Just look at the problem.

1
  • I don't see ModalInstanceCtrl defined in your HTML structure!! Commented Oct 24, 2014 at 14:57

2 Answers 2

1

You should do following in ModalInstanceCtrl:

function ModalInstanceCtrl($scope, visitor11){
    $scope.visitor11 = visitor11;
}

To use variable in view, first it must be property of $scope object

Sign up to request clarification or add additional context in comments.

Comments

0

I solved it by modifying instance controller. I thought that 'return visitor' in resolve is passing this variable to my html but it was passing this to ModalInstanceCtrl controller. Just added one line to use this in my html

visitorCenter.controller('ModalInstanceCtrl', function ($scope, $modalInstance, visitor11)        
{
    $scope.visitor11 = visitor11;
    .
    .
    .
}

Now this variable 'visitor11' is ready to be used in html.

1 Comment

If you looked at my answer, you would not have spent 15 days figuring out what was wrong :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.