locked
The controller with the name 'FunctionHelloworld' is not registered.[Angular js error] RRS feed

  • Question

  • User81789783 posted

    Can y one help me . here is angular version i m using

    /**
    * @license AngularJS v1.7.8
    * (c) 2010-2018 Google, Inc. http://angularjs.org
    * License: MIT
    */

    here is code

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    	<meta charset="utf-8" />
        <script src="Scripts/angular.js"></script>
    </head>
    <body ng-app>
        <div ng-controller="FunctionHelloworld">
            Hello:
            {{message}}
        </div>
        <script>
            function FunctionHelloworld($scope) {
                $scope.message = "ERum";
            }
    
        </script>
    
    </body>
    
    </html>
    

    here is error

    angular.js:15567 Error: [$controller:ctrlreg] The controller with the name 'FunctionHelloworld' is not registered.
    https://errors.angularjs.org/1.7.8/$controller/ctrlreg?p0=FunctionHelloworld
    at angular.js:138
    at $controller (angular.js:11677)
    at setupControllers (angular.js:10708)
    at nodeLinkFn (angular.js:10493)
    at compositeLinkFn (angular.js:9832)
    at compositeLinkFn (angular.js:9835)
    at publicLinkFn (angular.js:9697)
    at angular.js:1965
    at Scope.$eval (angular.js:19393)
    at Scope.$apply (angular.js:19492)

    please not down that i m just beginner level with angular ,and this time i m sharing code with empty string after ng-app

    <body ng-app> also , i just need to print hello world..

    Tuesday, October 22, 2019 4:29 AM

All replies

  • User-719153870 posted

    Hi erum,

    angular.js:15567 Error: [$controller:ctrlreg] The controller with the name 'FunctionHelloworld' is not registered.

    I think in Angular, it's a different way to define a controller than:

    <script>
            function FunctionHelloworld($scope) {
                $scope.message = "ERum";
            }
    
        </script>

    First of all, you need to specify a range with ng-app and then specify the controller name with ng-controller.

    Please refer to AngularJS Controllers for more information about how to use AngualrJS controllers.

    Also, your code can be modefied like below:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    	<meta charset="utf-8" />
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
    </head>
    <body ng-app="myApp">
        <div ng-controller="FunctionHelloworld">
            Hello:
            {{message}}
        </div>
        <script>
            angular.module('myApp', []).controller('FunctionHelloworld', function ($scope) {
                $scope.message = "ERum";
            });
        </script>
    
    </body>
    </html>

    You can see the result below:

    Best Regard,

    Yang Shen

    Tuesday, October 22, 2019 6:35 AM