0

My code is like this

Controller.JS
    angular.module('RateRequestApp.controllers', []).controller('ReadOnlyController',  '$controller', function($scope, rateRequestService,$controller) {

    $controller('ModalDemoCtrl',{$scope : modalDCtrl });
    $scope.rateData = [];

    rateRequestService.getData().success(function(response) {
        $scope.rateData = response;
    }).error(function (data, status, headers, config) {

        modalDCtrl.openModal();
    });
});
angular.module('RateRequestApp.controllers').controller('ModalDemoCtrl', function ($scope, $modal, $log) {

    this.openModal = function (size) {

        var modalInstance = $modal.open({
            templateUrl: 'myModalContent.html',
            controller: 'ModalInstanceCtrl',
            size: size,

        });
    }; 
});
App.JS
angular.module('RateRequestApp', [
   'RateRequestApp.services',
   'RateRequestApp.controllers',
   'ui.bootstrap'
]);

Everything looks okay to me, But this throws an error

Error: [ng:areq] Argument 'ReadOnlyController' is not a function, got string

Can any one point out what I am doing wrong?

1 Answer 1

2

You are using the dependency declaration incorrectly. It needs to be wrapped in an array. Instead of:

.controller('ReadOnlyController',  '$controller', function($scope, rateRequestService,$controller) {
   // your stuff
});

Try:

.controller('ReadOnlyController',  ['$controller', function($scope, rateRequestService,$controller) {
   // your stuff
}]);

And even that isn't correct, because the names of the dependencies and the args need to match. Try:

.controller('ReadOnlyController',  ['$scope','rateRequestService','$controller', function($scope, rateRequestService,$controller) {
   // your stuff
}]);
Sign up to request clarification or add additional context in comments.

1 Comment

Yup, he beat me to it you must either use $injector or you need to wrap the function and dependency arguments in []. This answer should be accepted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.