droidnation droidnation - 3 months ago 489
AngularJS Question

Angular controller is not registered error

I am new to Angular JS and I am using the 1.6 version of it.

I have this


var myApp = angular.module("myApp", []);

"use strict";
myApp.controller("productController", function($scope, $http)

$scope.prd = prd.data;

And here my

"title":"20 Foot Equipment Trailer",
"description":"2013 rainbow trailer 20 feet x 82 inch deck area, two 5,000 lb axels, electric brakes, two pull out ramps, break away box, spare tire.",
"contact": {
"name":"John Doe",
"phone":"(555) 555-5555",
"Parts and Accessories"
"image": "http://www.louisianasportsman.com/classifieds/pics/p1358549934434943.jpg",

Now here is my html page where I specified the ng-app and ng-controller:

<body ng-app="myApp" ng-controller="productController">
<div class="row">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<a class="navbar-brand" href="#">Brand</a>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Add <span class="sr-only">(current)</span></a></li>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
<button type="submit" class="btn btn-default">Submit</button>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->

<div class="col-sm-4" ng-repeat="product in prd">
<div class="panel panel-primary">
<div class="panel-heading">{{product.title}}</div>
<div class="panel-body">
<img ng-src="{{product.image}}">
{{product.price | currency}}
<div class="panel-footer">a</div>

<script src="angular/angular.js"></script>
<script src="scripts/appTest.js"></script>

I am still getting the following error which is new for me:

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

Any help is appreciated.


Its because of your Immediately Invoked Function Expression. you have to change it like below :

var myApp = angular.module("myApp", []);

  "use strict";
  app.controller("productController", function($scope, $http){
      $scope.prd = prd.data;