javascript - Angular: reference currently instantiated controller -
is there way reference instantiated controller object within controller's definition? i'd $compile
modal , bind same controller that's creating modal.
here's simplified version of i'd do, this_controller_instance
reference controller instance.
angular.module('foo') .controller('barcontroller', function($scope, $rootscope){ $scope.openmodal = function(){ var modalel = $('<div class="modal">modal stuff here</div>'); var controller = this_controller_instance; modalel.contents().data('$ngcontrollercontroller', this_controller_instance); $compile(modalel)($scope); $('body').append(modalel); } });
as noted above:
the current controller
this
. solution problem is:
angular.module('foo') .controller('barcontroller', function($scope, $rootscope){ var self = this; $scope.openmodal = function(){ var modalel = $('<div class="modal">modal stuff here</div>'); var controller = self; modalel.contents().data('$ngcontrollercontroller', controller); $compile(modalel)($scope); $('body').append(modalel); } });
Comments
Post a Comment