0

I'm trying to implement angular UI modal and trying to set few default values before create person screen is opened. Say a new person object like below:

  var person = {};
  person.name = 'default';

In this function

modalCtrl.open = function(size) {

    var person = {};
    person.name = 'default';

    console.log('person-->' + person);
    console.log('person.name-->' + person.name);

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

I can do the same thing in update flow if the object is passed by a called.

My assumption is that I should be able to create a new object and resolve it to display few default values on create screen. Does anyone know why I can't do it? Here is the plunker:

http://plnkr.co/edit/XLrbQpDoV8bx1vktbygx?p=preview

1 Answer 1

1

You can resolve it.. just need to add person as a dependency to the modal instance controller

app.controller('ModalInstanceCtrl', ['$scope', '$modalInstance', 'person',
  function($scope, $modalInstance, person) {
    alert(person.name);
    $scope.ok = function() {
      $modalInstance.close($scope.person);
    };

    $scope.cancel = function() {
      $modalInstance.dismiss('cancel');
    };
  }
]);
Sign up to request clarification or add additional context in comments.

Comments

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.