0

I have a very simple Angular controller set up, but the code inside its constructor isn't running. Here are the relevant pieces:

conversationcontrollers.js:

var exampleApp = angular.module('exampleApp',[]);

console.log('file loaded');

exampleApp.controller('ConversationController', ['$scope',
    function($scope) {
        console.log('controller constructor loads');
    }
]);

conversation.html:

...
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<script src='/static/js/conversationcontrollers.js'></script>
...
<div ng-controller="ConversationController">
</div>
...

The files both load correctly according to the browser. But the only results from the console are:

file loaded

Can anyone help?

5
  • Do you have ng-app in your html element? What is the error you are getting? Commented Feb 25, 2014 at 17:17
  • Do you have ng-app declared in conversation.html? Commented Feb 25, 2014 at 17:17
  • show your full html, sounds likee your missing ng-app Commented Feb 25, 2014 at 17:17
  • Make sure you have in your html, proper html tag <html ng-app="exampleApp"> Commented Feb 25, 2014 at 17:21
  • Another note, you are creating a new angular module with the [] parameter. If conversation.html is a partial loaded in ng-view, you may want to be using the parent angular module. Commented Feb 25, 2014 at 17:21

1 Answer 1

3

You'll also need an ng-app. This tells angular which part of your page is the angular application.

<div ng-app="exampleApp" ng-controller="ConversationController">
</div>
Sign up to request clarification or add additional context in comments.

Comments

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.