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

ng-model doesn't work with custom directive if the directive replaces content

Open bratc opened this issue 13 years ago • 8 comments

I've faced with following problem. I created directive that replace existing element with new one and used it like this:

When I ran this code I received an error: Error: [$compile:ctreq] Controller 'ngModel', required by directive 'myDirective', can't be found! http://errors.angularjs.org/1.2.0-rc.3/$compile/ctreq?p0=ngModel&p1=myDirective at http://localhost:63343/demo-app/lib/angular/angular.js:78:12 at getControllers (http://localhost:63343/demo-app/lib/angular/angular.js:5288:19) at http://localhost:63343/demo-app/lib/angular/angular.js:5294:24 at Array.forEach (native) at forEach (http://localhost:63343/demo-app/lib/angular/angular.js:213:11) at getControllers (http://localhost:63343/demo-app/lib/angular/angular.js:5293:11) at nodeLinkFn (http://localhost:63343/demo-app/lib/angular/angular.js:5436:35) at http://localhost:63343/demo-app/lib/angular/angular.js:5589:13 at http://localhost:63343/demo-app/lib/angular/angular.js:6672:11 at deferred.promise.then.wrappedCallback (http://localhost:63343/demo-app/lib/angular/angular.js:9769:81)

angular.js:8296

This directive works perfectly well with 1.2rc2 but doesn't work with 1.2rc3

bratc avatar Oct 23 '13 13:10 bratc

@bratc Are you using the template or templateUrl property to specify the HTML? I had the same issue, but it did only occure if using templateUrl, but worked fine with template.

FedericoElles avatar Nov 18 '13 14:11 FedericoElles

@FedericoElles I'm using templateUrl because in my case it's inconvenient to use template (far too big)

bratc avatar Nov 20 '13 12:11 bratc

Happened to me as well. Using template is not a solution.

roypeled avatar Nov 20 '13 13:11 roypeled

Is there a workaround for this? I need to use templateUrl.

mkondwilkar avatar Dec 17 '13 08:12 mkondwilkar

There is no code in your post. Can you post the code or even better a plunker?

Narretz avatar Dec 17 '13 08:12 Narretz

It works again with version 1.2.3 and later

bratc avatar Dec 17 '13 08:12 bratc

@petebacondarwin This can be closed. Just pinging you because you seem to be currently closing some stuff.

Narretz avatar Dec 17 '13 15:12 Narretz

Thanks @Narretz . Please do ping me for issues that can be closed :-) Makes my day.

petebacondarwin avatar Dec 17 '13 22:12 petebacondarwin