I have an element directive and an attribute directive:
<my-element my-attribute="value"></my-element>
my-attribute is a directive which require ngModel:
app.directive('myAttribute', [
function() {
var definition = {
restrict: 'A',
require: 'ngModel',
link: function ($scope, $element, $attrs, ctrl) {...}
}
return definition;
my-element can be used without ng-model but the template of my-element contains input which always has ng-model. The my-attribute should be removed from my-element and added to input inside my-element. In my compile function in my-element directive I have:
var value = element.attr('my-attribute');
element.remove('my-attribute');
element.find('input').attr('my-attribute', value);
It works ok when attribute directive doesn't have require: 'ngModel'. But if I have ngModel required I get:
Error: [$compile:ctreq] Controller 'ngModel', required by directive 'myAttribute', can't be found!
Why? How can I fix this?