plunk: http://plnkr.co/edit/85Wl5W If I use the $modalInstance on the same controller(modalController.js), without being in a modal, angular gets frozen.
I just want to
I haven't found a clean solution yet, the best workaround I found, to avoid writing the same code twice was to extend the modal controller like this:
$.extend(this, $controller('NormalCtrl', {$scope: $scope}));
full controller:
.controller('ModalCtrl', ['$scope', '$controller', '$modalInstance',
function ($scope, $controller, $modalInstance) {
//with this line here:
// Initialize the super class and extend it.
$.extend(this, $controller('NormalCtrl', {$scope: $scope}));
// Opens a search result
$scope.openResult = function() {
$modalInstance.close($scope.selectedRow);
};
// Called when the cancel button is pressed
$scope.back = function() {
$modalInstance.dismiss('cancel');
};
}]);
That way, I can re-use the same code, without having to rewrite it all over again and I can override the functions that I want to do smth different to the original controller.
Hope I helped some people out there,
Alex