i'm trying to add the attribute ng-model inside of all elements and directives that have the "name" attribute on it, but for some reason when i use the transclude function of my link function the directives removes the ng-model that i added and then angular throws me the error:
Error: [$compile:ctreq] Controller 'ngModel', required by directive 'someDirectiveThatRequiresNgModel', can't be found!
When i see the DOM in my chrome developers tools the ng-model is removed (is removed from directive elements but not from simple input elements) after i added it using this code:
compile: function(element, attrs){
return {
pre: function ($scope, $element, $attrs, ctrl, transclude) {
},
post: function($scope, $element, $attrs, ctrl, transclude){
var initializePromise = $scope.__initialize();
initializePromise.then(function(){
transclude($scope, function (clone, scope) {
var inputs = clone.find('[name]');
$.each(inputs, function (index, input) {
var ainput = angular.element(input);
ainput.attr('ng-model', 'someValidScopeAttribute');
$compile(ainput)($scope);
});
$element.prepend(clone);
});
});
}
}
},
Why the attribute is removed when the directive is compiled inside the Transclude function?, how I can achieve what I need?