user2851669
user2851669

Reputation:

use a bootstrap modal without making a seperate controller

I am using a bootstrap modal

Controller.js -

    $scope.open = function() {
    var modalInstance = $modal.open({
        animation: true,
        templateUrl: 'views/template.html',
        controller: 'controller2',
        resolve: {
            items: function() {
                return $scope.values;
            }
        }
    });
    modalInstance.result.then(function(values) {
        $scope.new_value = values;
    }, function() {

    });
};

I don't want to create a new controller since the modal should show values which are constantly changing in the current controller. What should I pass in place of controller2 if I modal to be in the same controller?

Upvotes: 0

Views: 780

Answers (1)

yvesmancera
yvesmancera

Reputation: 2925

You could use the scope option instead of the controller:

$scope.open = function() {
    var modalInstance = $modal.open({
        animation: true,
        templateUrl: 'views/template.html',
        scope: $scope,
        resolve: {
            items: function() {
                return $scope.values;
            }
        }
});
modalInstance.result.then(function(values) {
        $scope.new_value = values;
    }, function() {

    });
};

Upvotes: 2

Related Questions