Reputation: 674
I have a page where I have a button to launch a modal. Both pages has its own controllers. The question is how to get variable from page in modal controller?
Upvotes: 0
Views: 945
Reputation: 20033
You pass data to your modal controller using resolve
.
var modalInstance = $modal.open({
templateUrl: 'template.html',
controller: 'MyModalCtrl',
resolve: {
variableToPass: function () {
return $scope.items;
}
}
});
Then you define your modal controller like this
myApp.controller('MyModalCtrl', ['$scope', $modalInstance'', 'variableToPass', function($scope, $modalInstance, variableToPass) {
...
}]);
Alternatively, or complementary, you can pass the whole $scope
like this
var modalInstance = $modal.open({
templateUrl: 'template.html',
controller: 'MyModalCtrl',
scope: $scope
});
Upvotes: 1