Javascript 在transclude函数中添加ng模型属性
我试图在所有元素和指令中添加属性ng model,这些元素和指令上都有“name”属性,但由于某种原因,当我使用link函数的transclude函数时,这些指令删除了我添加的ng model,然后angular向我抛出错误: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
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我将尝试您的建议,谢谢。可能的副本