Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在transclude函数中添加ng模型属性_Javascript_Angularjs_Angularjs Ng Transclude - Fatal编程技术网

Javascript 在transclude函数中添加ng模型属性

Javascript 在transclude函数中添加ng模型属性,javascript,angularjs,angularjs-ng-transclude,Javascript,Angularjs,Angularjs Ng Transclude,我试图在所有元素和指令中添加属性ng model,这些元素和指令上都有“name”属性,但由于某种原因,当我使用link函数的transclude函数时,这些指令删除了我添加的ng model,然后angular向我抛出错误: Error: [$compile:ctreq] Controller 'ngModel', required by directive 'someDirectiveThatRequiresNgModel', can't be found! 当我在chrome devel

我试图在所有元素和指令中添加属性ng model,这些元素和指令上都有“name”属性,但由于某种原因,当我使用link函数的transclude函数时,这些指令删除了我添加的ng model,然后angular向我抛出错误:

Error: [$compile:ctreq] Controller 'ngModel', required by directive 'someDirectiveThatRequiresNgModel', can't be found!
当我在chrome developers工具中看到DOM时,ng模型在我使用以下代码添加后被删除(从指令元素中删除,但不是从简单的输入元素中删除):

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);
                });
             });
         }
     }
},

在Transclude函数中编译指令时,为什么要删除属性?如何实现我需要的功能?

您是否尝试过使用
ng attr-
预写属性?在
元素上的示例
高度
之前,我已经在保留属性中遇到过这种情况。您所说的从指令中删除而不是从简单输入元素中删除是什么意思?如何从指令中删除某些内容?我猜你指的是元素。在v.1.2中已经进行了更改,因此您可能需要升级。如果只是为了增加获得帮助的机会。@zeroflagL我纠正了您关于指令元素的意思,我尝试了angular的几个最新版本,但没有任何更改,sal niro我将尝试您的建议,谢谢。可能的副本