【发布时间】:2014-04-05 08:12:30
【问题描述】:
我编写了一个指令来从范围字段生成输入字段,一切正常,除了父 ng-form 保持无效,即使指令中的 ng-form 无效。
这就是我检查表单状态的方式:
<ng-form name="parentForm" class="form-horizontal">
<form-field ng-model="input.name" field="fields[0]" ng-change="changed(input.name)"></form-field>
<form-field ng-model="input.age" field="fields[1]"></form-field>
<pre> parent form: valid : {{parentForm.$valid}}</pre>
</ng-form>
下面是链接功能
var linkFunction = function (scope, element, attrs) {
var fieldGetter = $parse(attrs.field);
var field = fieldGetter(scope);
var template = input(field, attrs); //genrate the template
element.replaceWith($compile(template)(scope)); //replace element with templated code
};
我想问题是我需要编译父元素而不是元素本身才能使验证工作,但不确定如何去做
element.replaceWith($compile(template)(scope));
【问题讨论】:
标签: angularjs angularjs-directive