angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

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

Open cmplank opened this issue 12 years ago • 3 comments

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

cmplank avatar Apr 09 '14 19:04 cmplank

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.

caitp avatar Apr 09 '14 23:04 caitp

It seems similar to #7059

lefos987 avatar Apr 09 '14 23:04 lefos987

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

caitp avatar Apr 09 '14 23:04 caitp