0

I'm opening a "popup" using

$scope.dialog = ngDialog.open({ template: 'addSurveyQuestion', controller: 'EventSurveysCtrl', scope: $scope });

Within the template I call a function, which creates an AJAX request but upon me pushing that data to $scope using $scope.eventSurveyQuestions.push({data here}); it doesn't appear in the main $scope. Its as if there are 2 $scope variables, one for main page and one for ngDialog.

How can I add data to the main $scope from within a process that was initiated from within an ngDialog popup?

Ste
  • 591
  • 1
  • 9
  • 20

3 Answers3

0

I know nothing about ngDialog but I took a look into its documentation about the scope property.

Scope object that will be passed to the dialog. If you use a controller with separate $scope service this object will be passed to the $scope.$parent param.

You don't show very much of how you built your actual controller so I can just guess that you may want to access $scope.$parent instead of plain $scope.

You may also be interested in this question.

Community
  • 1
  • 1
Fidel90
  • 1,828
  • 6
  • 27
  • 63
0

you can add data to the main scope by scope.$parent or $scope.$parent

Possibly you can use $rootScope to set and get variables values from there

0

No need to use scope in dialog.open, if you opening your dialog from 'main scope'.

Try

$scope.dialog = ngDialog.open({
    template: 'addSurveyQuestion',
    controller: 'EventSurveysCtrl',
});

and, in your dialog controller -

app.controller('EventSurveysCtrl', ["$scope",.... fucntion($scope,...) {
    //now the '$scope' is your main scope
}
VISHAL DAGA
  • 4,132
  • 10
  • 47
  • 53