Angularjs 通过$compile解析的HTML,ng模型未单独绑定以进行ng repeat

Angularjs 通过$compile解析的HTML,ng模型未单独绑定以进行ng repeat,angularjs,angularjs-ng-repeat,angular-ngmodel,angular-directive,Angularjs,Angularjs Ng Repeat,Angular Ngmodel,Angular Directive,我正在构建一个角度模块,它将允许动态构建表单 选择元素后,HTML将添加到模型中。模型连接到ng repeat元素 <div ng-repeat="item in list1 track by $index"> <div compiledom="item.content"></div> </div> 我正在使用一个自定义指令编译馈送到模型的HTML .directive('compiledom', function($compile) {

我正在构建一个角度模块,它将允许动态构建表单

选择元素后,HTML将添加到模型中。模型连接到
ng repeat
元素

<div ng-repeat="item in list1 track by $index">
  <div compiledom="item.content"></div>
</div>
我正在使用一个自定义指令编译馈送到模型的HTML

.directive('compiledom', function($compile) {
 return function(scope, element, attrs) {
  scope.$watch(
    function(scope) {
      return scope.$eval(attrs.compiledom);
    },
    function(value) {
      element.html(value);
      $compile(element.contents())(scope);
    }
  );
 }
})
并使用第二个指令将模型数据绑定到HTML中的输入字段

.directive('dynamicModel', function($compile) {
 return function(scope, element, attrs) {
  scope.$watch(attrs.dynamicModel, function(dynamicModel) {
    if (attrs.ngModel || attrs.ngModel == dynamicModel || !dynamicModel) return;

    element.attr('ng-model', 'item.inputValue'); <---------- bound here

    if (dynamicModel == '') element.removeAttr('ng-model');
    element.unbind();
    $compile(element)(scope);
  });
 }
})
指令('dynamicModel',函数($compile){ 返回函数(范围、元素、属性){ 作用域.$watch(attrs.dynamicModel,函数(dynamicModel){ if(attrs.ngModel | | attrs.ngModel==dynamicModel | |!dynamicModel)返回;
element.attr('ng-model','item.inputValue');事实证明,我的指令很好

当我添加到我的模型中时,我使用了
.slice
。这导致了反射问题。使用
angular.copy
创建了一个geniune克隆,允许我寻找的隔离


$scope.list1[x]=angular.copy($scope.list5[x]);

事实证明,我的指令很好

当我添加到我的模型中时,我使用了
.slice
。这导致了反射问题。使用
angular.copy
创建了一个geniune克隆,允许我寻找的隔离

$scope.list1[x]=angular.copy($scope.list5[x]);

.directive('dynamicModel', function($compile) {
 return function(scope, element, attrs) {
  scope.$watch(attrs.dynamicModel, function(dynamicModel) {
    if (attrs.ngModel || attrs.ngModel == dynamicModel || !dynamicModel) return;

    element.attr('ng-model', 'item.inputValue'); <---------- bound here

    if (dynamicModel == '') element.removeAttr('ng-model');
    element.unbind();
    $compile(element)(scope);
  });
 }
})