1

I can't for my live figure out why Angular is not working along.

I defined a simple app and controller:

angular.module('weatherApp', [])
    .controller("weatherController", function() {
        console.log('weather controller created!');
    });

In my HTML I have:

<div ng-app="weatherApp" ng-controller="weatherController"></div>

Nothing else. I'm using AngularJS 1.2.28 (constrained by the project I'm working with). Upon loading of the page, my console logs the expected text above. However, immediately following it is the following error:

Error: [ng:areq] http://errors.angularjs.org/1.2.28/ng/areq?p0=weatherController&p1=not%20a%20function%2C%20got%20undefined

Why is it doing this when it's (apparantly) working just fine?

When I'm not using a module or controller and simply define a global weatherController function, everything again works just fine.

I've looked around, but can't find anything about this being specific to 1.2.28 or something.

Lennard Fonteijn
  • 2,561
  • 2
  • 24
  • 39
  • 2
    possible duplicate of http://stackoverflow.com/a/28728380/2435473 – Pankaj Parkar Jan 11 '16 at 19:39
  • If its related to global controller declaration, how would I tell 1.2.28 to not allow it? Or look for both with fallback or alike? It's weird because example on the web using 1.2.28 are not any less simple than what I just posted and it seems to work fine for them. – Lennard Fonteijn Jan 11 '16 at 19:41
  • have you tried to place ng-app and ng-controller into distinct tags? – Paulo Scardine Jan 11 '16 at 19:47
  • there shouldn't be error..it will automatically work for both..look at [Fiddle](http://jsfiddle.net/k66Za/173/) which has `angular 1.2.1` – Pankaj Parkar Jan 11 '16 at 19:47
  • @PauloScardine Yes I did, it did not help. – Lennard Fonteijn Jan 11 '16 at 19:48
  • @Pankaj Parkar That's what I thought too, but for some reason its throwing an error for nothing. Since it executes the body of the controller just fine. – Lennard Fonteijn Jan 11 '16 at 19:48
  • Where do you define your angular app and controller and how do you load that script in to your html? Show full JS and html files. – Hamlet Hakobyan Jan 11 '16 at 19:48
  • @HamletHakobyan Angular itself is dependency injected. The angular app is defined in a .js file which I include using a proper script tag in the head. – Lennard Fonteijn Jan 11 '16 at 19:49
  • https://plnkr.co/edit/Im8F1nAIlecqEryjhwZD?p=preview thats a working fiddle of your example, so perhaps you haven't provided enough info? Did you reference in your HTML the javascript file that has your controller? – AlexD Jan 11 '16 at 19:50
  • @AlexD Very weird, I have precisely that, except for angular.js coming from ClientDependency (a .NET dependency manager). I'm starting to suspect the ClientDependency is doing weird things now. – Lennard Fonteijn Jan 11 '16 at 19:53
  • Here is [Plunker](http://plnkr.co/edit/q4YtaSU2LodHMmRQRlK0?p=preview) which works perfect. – Hamlet Hakobyan Jan 11 '16 at 19:53
  • I just disabled the ClientDependency injection of angular and the error is gone. I have no idea why it would be throwing this error... – Lennard Fonteijn Jan 11 '16 at 19:58
  • Open a new question with the relevant ClientDependency configuration and code as it seems its not related to AngularJS coding. – AlexD Jan 11 '16 at 19:59

1 Answers1

0

I figured it out! Apparently the ClientDependency was loading another app.js which does a lot more with AngularJS than my simple controller. The two simply couldn't co-exist!

Since I didn't need the other app in this particular page, I excluded it from the ClientDependency and voilá, fixed!

Lennard Fonteijn
  • 2,561
  • 2
  • 24
  • 39