1

I am new with Angularjs , here is my code,

angular.module('remoteApp')
  .controller('ScreensavertabCtrl', function ($scope, $modal, $log, $state,Screensaverchpwservice,  
    Screensaverchpwgetservice) { 
      $scope.screensaverData = {
         screensaver:{
           pwProtect: '1'
         }
       };

  $scope.pwProtectOpen = function () {
    if($scope.screensaverData.screensaver.pwProtect == true){
      var modalInstance = $modal.open({
        templateUrl: 'pwProtectModalContent.html',
        controller: pwProtectModalInstanceCtrl
    });
  }     
};

var pwProtectModalInstanceCtrl = function ($scope, $modalInstance) {
  $scope.pwProtectCancel = function () {
    $modalInstance.dismiss('cancel');
    console.log($scope.screensaverData.screensaver.pwProtect)
  };

};});

when I enable pwProtectCancel function , I want to get $scope.screensaverData.screensaver.pwProtect

value, I tried to use '$scope.$parent.screensaverData.screensaver.pwProtect' is not work?

I am so confused about that,

anyone ideas?

1
  • 1
    Assuming you have nested the controllers properly in the HTML, your code should work as is. Commented Oct 2, 2013 at 7:29

1 Answer 1

5

Change you $modal service call to

var modalInstance = $modal.open({
        templateUrl: 'pwProtectModalContent.html',
        controller: pwProtectModalInstanceCtrl
        scope:$scope
}

and you should get the data no the modal scope.

The documentation mentions about scope option

scope - a scope instance to be used for the modal's content (actually the $modal service is going to create a child scope of a a provided scope). Defaults to $rootScope

The default it gets is rootscope.

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.