2017-02-23 93 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