Play Games

Search This Blog

Thursday, September 22, 2016

Uncaught ReferenceError: angular is not defined

Problem : This error will come when we are referring angular like "var app = angular.module('myApp',[]);" before loading angular.js files.
Sample Code that leads to error:
<script>
var app = angular.module('myApp',[]);

app.directive('myDirective',function(){

return function(scope, element,attrs) {
element.bind('click',function() {alert('click')});
};

});
</script>
<script src="lib/angular/angular.js"></script>
Solution : Just include angular.js files at the top of page before referring it.
Modify above code like this
<script src="lib/angular/angular.js"></script>
<script>
var app = angular.module('myApp',[]);

app.directive('myDirective',function(){

return function(scope, element,attrs) {
element.bind('click',function() {alert('click')});
};

});
</script>

No comments:

Post a Comment