私は成功せずに角度ディレクティブで検証と戦っています。
name プロパティをディレクティブ テンプレートに送信すると、form.name.$error オブジェクトが未定義のようです。テンプレート内で固定の name-attribute を使用する場合、$error オブジェクトは問題ありませんが、もちろんすべての要素で同一です。
htmlは次のとおりです。
<form name="form" novalidate>
<p>
<testvalidation2 name="field1" form="form" field="testfield4" required="true">
</testvalidation2>
</p>
</form>
ディレクティブは次のようになります。
app.directive('testvalidation2', function(){
return {
restrict: 'E',
scope: {
ngModel: '=',
newfield: '=field',
required: '=required',
form: '='
},
templateUrl: 'template2.html',
link: function(scope, element, attr){
scope.pattern = /\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/;
scope.name = attr.name;
}
} // 戻ります });`
そして最後にテンプレート:
<div>
<input name="{{name}}" type="text" ng-model="newfield" ng-required="required" ng-pattern="pattern"> {{FIELD}}</input>
<span ng-show="form.name.$error.required">Required</span>
<span ng-show="form.name.$error.pattern"> Invalid </span>
<p>Output {{form.name.$error | json}}</p>
</div>
Angular Validation Problemのプランカーを作成しました 。誰かが私が戦いに勝つのを手伝ってくれたら幸いです。
マイケル