Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

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

Closed
cmplank opened this issue Apr 9, 2014 · 3 comments

Comments

@cmplank
Copy link

cmplank commented Apr 9, 2014

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

@caitp
Copy link
Contributor

caitp commented Apr 9, 2014

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.

@lefos987
Copy link
Contributor

lefos987 commented Apr 9, 2014

It seems similar to #7059

@caitp
Copy link
Contributor

caitp commented Apr 9, 2014

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

@lefos987 lefos987 added this to the Backlog milestone Apr 10, 2014
caitp added a commit to caitp/angular.js that referenced this issue Apr 10, 2014
Previously, ctreq would possibly reference the incorrect directive name,
due to relying on a directiveName living outside of the closure which
throws the exception, which can change before the call is ever made.

This change saves the current value of directiveName as a property of
the link function, which prevents this from occurring.

Closes angular#7062
caitp added a commit to caitp/angular.js that referenced this issue Apr 10, 2014
Previously, ctreq would possibly reference the incorrect directive name,
due to relying on a directiveName living outside of the closure which
throws the exception, which can change before the call is ever made.

This change saves the current value of directiveName as a property of
the link function, which prevents this from occurring.

Closes angular#7062
caitp added a commit that referenced this issue Apr 15, 2014
Previously, ctreq would possibly reference the incorrect directive name,
due to relying on a directiveName living outside of the closure which
throws the exception, which can change before the call is ever made.

This change saves the current value of directiveName as a property of
the link function, which prevents this from occurring.

Closes #7062
Closes #7067
@caitp caitp closed this as completed in 1192531 Apr 15, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants