Wai Yan Hein Wai Yan Hein - 20 days ago 5x
AngularJS Question

Cannot declare controller in Angular Js

I am developing an Web Application. In my application, I am using Angular JS. Frankly, I am new to Angular JS. But now I am having a problem my declaring controller. Please see my code below.

//files references
var app = angular.module('memeApp',['ngRoute','ui.bootstrap']);
<nav class="nav-bar">
<a href="page1">Home</a>
<a href="page2">Account</a>
<div class="content" ng-app="memeApp" ng-controller="DefaultController">

As you can see I did nothing yet. I declare a controller named DefaultController. So when I check log, it is giving me following error.
enter image description here

So my controller is totally not working. When I add js code for controller as well. If I removed controller directive, errors gone. So please what is wrong with my code? Please why my controller not working? Please help me.


You need to define a controller function 'DefaultController' before you use it in html div tag.

Add below code in your script tag.

app.controller('DefaultController', ['$scope', function($scope){