我试图在具有" name"的所有元素和指令中添加属性ng-model。它的属性,但由于某种原因,当我使用我的链接函数的transclude函数时,指令删除我添加的ng模型然后角度抛出错误:
Error: [$compile:ctreq] Controller 'ngModel', required by directive 'someDirectiveThatRequiresNgModel', can't be found!
当我在我的chrome开发人员工具中看到DOM时,在使用此代码添加ng-model后,删除了ng-model(从指令元素中删除,但不是从简单的输入元素中删除):
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函数中编译指令时删除了属性?我怎样才能实现我的需要?