2017-02-23 43 views
0

我有角狀的部件,其HTML部分被定義如下: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); 

}; 

組件在ng重複使用如下:

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

一切工作正常,如果我不包括組件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,對吧?

謝謝。

+0

'ng-change'需要綁定變量('ng-model')。你不能在div中使用它。 – Mistalis

回答

0

你不能在一個div使用ng-change

它要求ng-model ..即使用ng-change你將不得不使用ng-model強制只適用於像複選框,單選,文本等輸入元素。

在你的情況下使用ng-click

以下是Docsng-change

+0

謝謝Saurabh,非常感謝 – Journeyman