AngularJS Error: The controller with the name myCtrl is not registered

Last Reply 8 months ago By dharmendr

Posted 8 months ago

I am getting error in console that my controller is not registered.

<!DOCTYPE html>
<html>
	<head>
		<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
	</head>
	<body>
		<div ng-app="myApp" ng-controller="myCtrl">
		    <div>
		    	<h1>Add Your Quotes</h1>
		    </div>
		    <div>
		    	<button name=addQuote ng-click = "addQuoteBtn()">Add Quote</button>
		    </div>
		    <div ng-if="isVisible">
		    	<textarea rows="4" cols="50" placeholder="Add Quotes Here"></textarea>
		    </div>
		</div>
		<script>
			var app = angular.module('myApp', []);

			app.controller = ('myCtrl', ['$scope', function($scope){
				$scope.isVisible = false;
				$scope.addQuoteBtn = function(){
					$scope.isVisible = true;
				}
			}]);
		</script>
	</body>
</html>

 

Posted 8 months ago

Hi jeenu123,

Change your code with the below code.

<script type="text/javascript">
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function ($scope) {
        $scope.isVisible = false;
        $scope.addQuoteBtn = function () {
            $scope.isVisible = true;
        }
    });
</script>

You can refer the below article for more details on ng-click.

Set TextBox value on Button Click using AngularJS