简体   繁体   English

ng-change不适用于ngTagInput

[英]ng-change is not working with ngTagInput

I am new in angular js .Here I am trying to call getTagsName function when user starts writing into the textbox.According to the keyword ,autocomplete suggestion will appear.But in my case ng-change is not working it seems ...Can anyone help me out.. 我是angular js的新手。在这里,我试图在用户开始写入文本框时调用getTagsName函数。根据关键字,将显示自动完成建议。但是在我的情况下ng-change无法正常工作...似乎有人...帮帮我..

my html: 我的html:

<tags-input ng-model="tags2" display-property="name" ng-change="getTagsNames()">
  <auto-complete source="loadTags($query)"></auto-complete>
</tags-input>

my js: 我的js:

$scope.getTagNames = function() {
     $scope.loadTags = function(query) {
         return $http.get('tags.json');
     };
};

I think ng-change() directive will not work because onChange() functionality will never be executed when the tags model changes on ngTagInput . 我认为ng-change()指令将不起作用,因为当标记模型在ngTagInput上更改时,onChange()功能将永远不会执行。

use on-tag-added="getTagNames()" and on-tag-removed="getTagNames()" 使用on-tag-added="getTagNames()"on-tag-removed="getTagNames()"

 <tags-input ng-model="tags2" display-property="name" on-tag-added="getTagNames()" on-tag-removed="getTagNames()" >

Or u can watch the changes with $scope.$watch , as the tags are arrays or objects $scope.$watchCollection can be used 或者,您可以使用$scope.$watch更改,因为标签是数组或对象$scope.$watchCollection

 $scope.$watchCollection('tags2',function(){
    //execute the code on the changes

});

refer : http://mbenford.github.io/ngTagsInput/documentation/api 参考: http : //mbenford.github.io/ngTagsInput/documentation/api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM