0

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?

2
  • please try and google this . If you then have any doubts please ask here. Commented Apr 30, 2015 at 16:47
  • Try using the un-minified version of angular.js whilst developing; the error messages are more verbose. Also, try and paste the actual link it gives you in the console error message Commented May 5, 2015 at 23:05

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Whilst this is correct, I don't think it would cause the error OP's getting
@Phil you are totally right, sorry!!! I fixed what was obviously wrong in the provided code (and didn't checked the error case). If message is not defined, angular will simply not render it.
It's impossible to tell without the entire error message but it appears to be an $injector issue which usually points to missing dependencies. Will just have to wait an see

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.