我是新来的:)
好的我有问题,我写了这样的脚本:
var app = angular.module('myApp', []);
app.directive('formInput', function() {
return {
restrict: 'E',
require: ['^form'],
link: function(scope, element, attrs, ctr)
{
var form = ctr[0];
var newEl = '<div class="control-group">' +
'<div class="controls">' +
'<input type="text" class="input-xlarge" id="' + attrs.formId + '" name="' + attrs.formId + '" required>' +
'</div>' +
'</div>' +
'<span ng-show="' + form.$name + '.' + attrs.formId + '.$error.required" class="help-block">Can\'t be blank</span>';
element.replaceWith(newEl);
}
}
});
和这个html:
<div ng-app="myApp">
<form name="test321" novalidate>
<form-input required form-id="iddd" label="test"></form-input>
</form>
</div>
我试图获得动态输入但验证工作正常,任何人都可以帮助我吗?