2014-06-19 27 views
0

我試圖實現一種方法,讓我的程序跟蹤用戶選擇並搜索的過濾器。輸入將位於文本框中,多個文本框中。我有每個選項(TimeStamp,SourceHost,UUID等)的文本框[我正在構建一個內部應用程序]。我需要能夠爲我的參數攜帶過濾器列表,並決定使用Array對象,但我遇到了一些問題。我初始化我的陣列但無法訪問其他功能中的信息攜帶數組橫跨多個角函數

app.controller("AppCtrl", function($http, $scope){ 
    var app= this; 
    $scope.filterList = []; 
    $scope.filterList.push("test"); 
    console.log($scope.filterList); 
    $scope.incData = function(page, filterList){ 
     callingIrrelevantFunction(page) 
     console.log($scope.filterList); 

第一個console.log輸出「test」。但是當我稍後使用它時(這不是我想要的用例,我只是想確保我可以將一個數組作爲範圍並在函數內調用它)輸出不正確。實際的預期用例是我將它追加到url的末尾。

編輯: 這裏是我的代碼共享版本:

app.controller("AppCtrl", function($http, $scope){ 
    var app = this; 
    $scope.filterList = []; 
    $scope.filterList.push("uuid=9022"); 
    $scope.filterList.push("source_host=Kani"); 

    function foobar(filterList){ 
     console.log("inside foobar"); 
     console.log(filterList); 
    } 
    foobar($scope.filterList); 
}); 

輸出 「[]」。

編輯#2:

當更改我的代碼只是一個數組,沒有 「$範圍。」在它的前面,代碼工作。但我相信我確實需要「$範圍」。因爲它與角度指令一起工作。

+0

從您的代碼。我看不出爲什麼你的數組不會有相同的內容。你可能有其他的功能來緩和內容。這裏沒有顯示的部分代碼。 –

+0

回聲@DayanMorenoLeon,你可以發佈你的整個控制器嗎? –

+0

對$ scope.filterList做了什麼更改'callingIrrelevantFunction(page)'? –

回答

0

問題是,您在「可共享」版本中將字符串值分配給$scope.filterList.push。你實際上從未將值推入數組中。