0

I worked on angular (2+) but i am newbie for angularJS. I am confused with how controllers are created in our project. I have learnt that controllers are created with below syntax

 AppConfig.controller("MasterController", ["$scope", "$http", "$window", "$rootScope", "$filter", "$uibModal", "$q",
    function ($scope, $http, $window, $rootScope, $filter, $uibModal, $q) {//to do}]

But, for uibModal controller, in our project i can't find the above syntax, instead controller are created as shown below for below uibmodal

var modalInstance = $uibModal.open({
                animation: true,
                backdrop: 'static',
                keyboard: false,
                templateUrl: 'Main_template.html',
                size: "slxModelPop",
                controller: MainController,
                resolve: {
                    scope: function () {
                        return $scope;
                    },
                    scopeData: function () {
                        return scopeData
                    }
                }
            });

The controller is defined as

var MainController= ["$scope", "$uibModal", "$uibModalInstance", "$http", "$compile", "$log", "$filter", "$window", "scope", "$timeout", "scopeData",
function ($scope, $uibModal, $uibModalInstance, $http, $compile, $log, $filter, $window, scope, $timeout, scopeData) {//to do}]

And it works fine, so can we create controller without using the controller constructor?

Bhavna
  • 257
  • 3
  • 8
  • You are still using the controller syntax, but in this case it's a property of the uibModal config. If you look inside of the `angular-ui-bootstrap/src/modal/modal.js` file you'll see that it takes that controller property and injects it into `scope`. There are more than one way to instantiate controllers – Kinglish Apr 10 '23 at 16:43

0 Answers0