AngularJS Error: $controller:ctrlreg The controller is not registered

Last Reply 6 months ago By dharmendr

Posted 7 months ago

 Hi

I am getting error like this-

controller register error in angular js code.

HTML

<div data-ng-app="myModule" class="container-fluid">        
    <div data-ng-controller="HomePagePhotosController" class="container">
        <div class="row">
            <div class="col-sm-12 col-md-12 col-lg-12 pagemargin" style="padding: 0px">
                <p class="aboutheading">
                    Our Gallery
                </p>
                <p class="aboutborder1" style="">
                </p>
                <div id="owlslider" class="owl-carousel owl-theme">
                    <div data-ng-repeat="p in GallaryPhotos" on-finish-render="getHomePageGallarySlider();"
                        class="item">
                        <img data-ng-src="{{p.PhotoPath}}" class="img-responsive owl" />
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

Code

Error: [$controller:ctrlreg] http://errors.angularjs.org/1.7.8/$controller/ctrlreg?p0=msgController
    at angular.js:99
    at angular.js:11677
    at ea (angular.js:10708)
    at p (angular.js:10493)
    at g (angular.js:9832)
    at g (angular.js:9835)
    at angular.js:9697
    at angular.js:1965
    at m.$eval (angular.js:19393)
    at m.$apply (angular.js:19492)

 

var app = angular.module('myModule', ['ngRoute']);
app.controller("msgController", function msgController($scope, $http) {

    $scope.Messages = [];
    $http({
        method: 'Get',
        url: '/Home/GetMessageDetails'
    }).then(function (response) {

        $scope.Messages = response.data;
        //    console.log($scope.Messages);

    }, function (error) {
        $scope.message = 'Unexpected Error';
    });
});

 

 

You are viewing reply posted by: dharmendr 6 months ago.
Posted 6 months ago

Hi iammann,

Your Html does not contain a div having data-ng-controller as msgController.

So assign data-ng-controller as msgController to an elemen.