2

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?

  • have you tried prepending your attributes with `ng-attr-`? I've had this happen with reserved attributes before example `height` on `` elements – scniro Jan 13 '15 at 19:59
  • What do you mean by _is removed from directives but not from simple input elements_? How can something be removed from a directive? I guess you mean element. There have been changes in v.1.2, so you might want to upgrade. If only to increase chances to get help. – a better oliver Jan 13 '15 at 22:25
  • @zeroflagL i correct what you mean about the directive element, i try with several latest versions of angular but nothing changes, sal niro i will try what you suggest, thanks. – Diego Fernando Murillo Valenci Jan 14 '15 at 00:57
  • possible duplicate of [Controller 'ngModel', required by directive '...', can't be found](http://stackoverflow.com/questions/21807834/controller-ngmodel-required-by-directive-cant-be-found) – Paul Sweatte Jul 25 '15 at 03:34

0 Answers0