2017-02-23 6 views
0

Iは、そのHTML部分は以下のように定義される角度成分を有する:NGリピート内NG変化

<div ng-class="{'chiptag2': !$ctrl.tag.isNew, 'chiptag-placeholder': $ctrl.tag.isNew, 'highlighted-tag': $ctrl.tag.isSelected}" 
     ng-change="$ctrl.onChipChange($ctrl.tag)" 
     ng-focus="$ctrl.onChipFocus($ctrl.tag)" 
     ng-blur="$ctrl.onChipBlur($ctrl.tag)" 
     contenteditable> 
{{$ctrl.tag.title}} 
</div> 

コントローラは、次のスニペットを有する:

this.onChipFocus = function(tag){ 

    console.log('editableChipComponent onChipFocus for new tag'); 

}; 

this.onChipChange = function(tag){ 

    console.log('editableChipComponent onChipChange has '+tag.title); 

}; 

this.onChipBlur = function(tag){ 

    console.log('editableChipComponent onChipBlur for '+tag.title); 

}; 

成分

<editable-chip-component 
     ng-repeat="tag in tagcategory.tags" 
     tag="tag" 
     bluemoon="$ctrl.toggleTagSelection(tag)" 
></editable-chip-component> 

すべての機能は、次のようにng-repeat内で利用されます。コンポーネントHTMLパーシャルのng-change属性しかし、すぐに、私は最初の項目を追加した後、NGリピート休憩後、NG-変更で追加し、コンソールには次のようなエラーを示して:

Error: [$compile:ctreq] http://errors.angularjs.org/1.6.1/$compile/ctreq?p0=ngModel&p1=ngChange 
    at angular.js:38 
    at V (angular.js:9722) 
    at n (angular.js:9645) 
    at g (angular.js:8881) 
    at n (angular.js:9635) 
    at angular.js:9980 
    at angular.js:16648 
    at m.$eval (angular.js:17972) 
    at m.$digest (angular.js:17786) 
    at m.$apply (angular.js:18080) 

誰もがこの上の任意の光を当てることができますか? ng-repeatでng-changeを持つことができるはずですよね?

ありがとうございました。 ng-changeを使用するng-model ...すなわちを求めているあなたはng-model強制的に使用する必要があります

+0

'ng-change'にはバインドされた変数(' ng-model')が必要です。あなたはdivでそれを使うことはできません。 – Mistalis

答えて

0

あなたはdivの上ng-changeを使用するカントそれはなど、チェックボックス、ラジオ、テキストなどの入力要素にのみ適用されます。

あなたのケースでは、ng-clickを使用してください。

ng-changeの場合はDocsです。

+0

ありがとうサウラバ、大変感謝しています – Journeyman