aakash mon
aakash mon

Reputation: 15

Uncaught Error: [$injector:modulerr] in Angular js

Here is my Angular code

angular.module('app',[]).controller('Ctrl', function ($scope) {
  $scope.message ='this is  message';
});

And my template code is

<div ng-app="app" ng-controller="Ctrl as ctrl">  
  <div>{{ ctrl.message }}</div>
  <img src="img.gif">
</div>

Issue is Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.13/$injector/modulerr?p0=app&p1=Error%3A%20…t%20d%20(file%3A%2F%2F%2FD%3A%2Fangular%2520js%2Fangular.min.js%3A17%3A381)

What could be the reason for this issue?

Upvotes: 0

Views: 486

Answers (1)

mrak
mrak

Reputation: 2906

In your controller you set a scope variable $scope.message but in the expression a variable which is defined as controllers instance variable is expected.

A valid expression for a scope variable is {{message}}.

A valid expression for a variable which is defined as controllers instance variable:

angular.module('app',[]).controller('Ctrl', function ($scope) {
  this.message = 'this is  message';
});

is {{ctrl.message}}

See this code example for a better illustration: http://plnkr.co/edit/HunVdGVYaC0HLjDPmWKl?p=preview

Upvotes: 1

Related Questions