私はngTagsInputを使用しており、モデルが変更されたときにモデルの検証を実行したいと考えています。これが私が達成したいことのプランカーです。
マークアップ:
<div ng-repeat="field in fields">
<tags-input ng-model="field.selectedData" max-tags="{{field.maxTags}}" enforce-max-tags placeholder="{{option.placeholder}}">
<auto-complete source="updateAutocomplete($query)"></auto-complete>
</tags-input>
</div>
フィールド/モデル:
$scope.fields = [
{
name: 'assay',
placeholder: 'Select one assay...',
maxTags: 1,
selectedData: [] // These are the models
},
{
name: 'cellLines',
placeholder: 'Select cell line(s)...',
maxTags: 5,
selectedData: []
},
...
]
最後に、私のenforceMaxTags
指示:
.directive('enforceMaxTags', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModelCtrl) {
ngModelCtrl.$parsers.push(function(value) {
console.log('link called');
});
}
};
})
enforceMaxTags
ディレクティブはコンパイルされていますlink
が、モデルが変更されても関数は呼び出されません。console.log
ただし、selectedData
フォーム送信時に正しいオブジェクトが入力されるため、データ バインディングは機能しているように見えます。私は何が欠けていますか?
前もって感謝します。