Angular.js: Error showing inaccurate causes: Error: [$compile:ctreq] Controller 'ngModel', required by directive 'ngClick', can't be found!

Created on 9 Apr 2014  ·  3Comments  ·  Source: angular/angular.js

This short fiddle http://jsfiddle.net/x3EtD/7/ shows errors in the console, but they are indicating a problem that doesn't exist. Namely, that the 'ngClick' directive requires 'ngModel' which it doesn't. There seems to be a bug with the way angular is filling in the blanks for this error message.

The problem in this case is that a custom directive that requires ngModel has been created for all input elements, but the checkbox in the example doesn't have one. Ironically, it doesn't actually break any functionality but spews out misleading errors in the console. Changing requires: 'ngModel' to requires: '?ngModel' takes care of the error in the fiddle.

Tracking this down was difficult as the errors pointed so explicitly to a problem with my use of ng-click rather than the real culprit.

I suspect that the error should say Error: [$compile:ctreq] Controller 'ngModel', required by directive 'input', can't be found!

OS: Ubuntu 12.04
Browsers: Chromium 33, Firefox 28
Angular versions tested: 1.2.1, 1.2.15

low inconvenient bug

All 3 comments

I just tested this with 1.2.16, and the problem occurs there too, it's interesting!

You'd expect the error to be thrown for the input dirctive, but it references ngClick instead. Very weird.

I'll look into this.

It seems similar to #7059

I think I see what's causing this, I'll have a fix in a few hours if no one beats me to it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brijesh1ec picture brijesh1ec  ·  3Comments

WesleyKapow picture WesleyKapow  ·  3Comments

th0r picture th0r  ·  3Comments

kishanmundha picture kishanmundha  ·  3Comments

guyandtheworld picture guyandtheworld  ·  3Comments