2017-10-13 85 views
1

我剛開始使用ngTagsInput角度庫,我在更新模型時遇到問題。我在ionicPopup中顯示標籤輸入,並且有趣的是標籤添加的事件觸發,它顯示$ scope.sites []被填充。ngTagsInput沒有綁定到模型

當我調用$ scope.test()時,該數組是空的。唯一能夠保持價值的上下文是與添加在標籤上的事件關聯的方法。

這裏是一個簡化的控制器,例如:

$scope.sites = []; 

$scope.addSites = function() { 
    // this works 
    console.log("In addSites"); 
    console.dir($scope.sites); 
} 

$scope.test = function() { 
    // in any other method $scope.sites is empty 
    console.dir($scope.sites); 
} 

在我看來,我有標籤元素定義爲:

<tags-input ng-model="sites" add-on-space="true" placeholder="Add Site Numbers" on-tag-added="addSites($tag)"></tags-input> 

我覺得它非常奇怪的是,一個$ scope變量可以包含的值我期望在圖書館事件的背景下,但不在此之外。

有沒有什麼特別的事情需要在綁定方面完成?據文件去,我沒有看到我失蹤。任何建議將不勝感激。

回答

1

經過大量的試驗和錯誤,我最終通過以下操作解決了這個問題。在我調用$ ionicPopup:「$涵蓋範圍」({}),但沒有NG-模式設置爲「$ parent.sites」這不是正確結合

<tags-input ng-model="$parent.sites" add-on-space="true" placeholder="Add Site Numbers" on-tag-added="addSites($tag)"></tags-input> 

我已經流逝。

希望這可以幫助他們把頭髮拉出來!