私のアプリでは、複数のフォームの中で、検証の完了したメール入力フィールドと同じディレクティブを使用しようとしています(最近使用された電子メールのリストから値を取得しますが、この質問には関係しません)。ディレクティブが使用される形式は、使用する場所によって異なりますので、ng-messages属性を動的にレンダリングする必要があります。ng-messagesに動的にフォーム名を設定しました
ダイナミックに設定するためにng-messagesを取得できましたが、期待通りに機能しません。ここでは、コードです:
form.html
<form name="joinForm">
<rt-recents-menu ng-model="vm.roomName"/>
</form>
directive.coffee
recents = angular.module 'rtRecents', ['ionic', 'ngMessages']
.factory('rtRecentsService', require './recentsService')
.directive('rtRecentsMenu', (rtRecentsService, $ionicActionSheet) ->
restrict: 'E'
template: require './recentsMenu.html'
scope:
ngModel: '=?'
require: ['?ngModel', '^form']
transclude: false
replace: false
link: (scope, element, attrs, ctrls) ->
ngModel = ctrls[0]
formCtrl = ctrls[1]
scope.formName = formCtrl.$name
module.exports = recents.name
directive.html私の場合は
<div class="email-line">
<input type="email"
name="roomName"
required
ng-model="ngModel"
ng-keydown="onKeyDown()"/>
<div id="email-error-messages" ng-messages="{{formName}}.roomName.$error" multiple role="alert">
<div ng-message="required" class="warn" translate>VALIDATION.EMAIL_REQUIRED_ERROR</div>
<div ng-message="email" class="warn" translate>VALIDATION.EMAIL_INVALID_ERROR</div>
</div>
</div>
これは痛みでした。この問題のためにグーグルグーグルは、多くのng-repeat生成入力フィールドを持つページ上で単一フォームを使用している人にしか与えません。把握するのに少し時間がかかりました。私はあなたのために以下の仕組みを教えてください。少し調整する必要がある場合は、私が助けてくれるかもしれません。 Happy ngCoding! –