2015-07-13 79 views
0

我是新的角度js。在這裏我試圖調用getTagsName函數,當用戶開始寫入文本框。根據關鍵字,自動完成建議將出現。但在我的情況下ng-改變是不工作似乎...誰能幫助我..ng-change與ngTagInput不兼容

我的html:

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

我的JS:

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

納克-change =「getTagsNames()」和js $ scope.getTagNames。字母「s」(getTagNames)缺失 – Navaneet

回答

1

我覺得NG-變化()指令不會因爲onCha工作當ngTagInput上的標籤模型發生更改時,nge()功能將永遠不會執行。

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

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

或U可以觀看與$scope.$watch的變化,因爲標籤是數組或$scope.$watchCollection可用於

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

}); 

對象是指:http://mbenford.github.io/ngTagsInput/documentation/api

+0

嘿,當我在ng模型中獲取數據時,我在{{tags}}這樣的頁面上顯示它,當我做這個數據顯示爲:[{「tagId」: 「2」,「tagName」:「Tag2」}](根據選定的數據),但當我顯示像{{tags.tagId}},它不工作,我的意思是什麼都沒有顯示。 –

+0

請幫我.. –

+0

@AshishSinha它的對象集合數組我認爲你已經使用ng-repeat來顯示數據或者你應該像這樣使用{{tags [0] .tagId}}(第一個數組對象) –

相關問題