Tuesday, 15 May 2012

javascript - Carrying Array Accross Multiple Angular Functions -



javascript - Carrying Array Accross Multiple Angular Functions -

i'm trying implement way programme maintain track of filters user has selected , searched through. input in text-box, multiple text boxes. have textbox each alternative (timestamp, sourcehost, uuid, etc) [i'm building internal application]. need able carry filter list parameters , decided utilize array object having issues. initialize array cannot access info in other functions

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);

the first console.log outputs "test". when utilize later on (this isn't intended utilize case wanted create sure scope array , phone call within of function) output isn't correct. actual intended utilize case appending end of url.

edit: here shareable version of code:

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); });

outputs "[]".

edit #2:

when alter code array, without "$scope." in front end of it, code works. believe need "$scope." work angular directives.

the problem assigning string values $scope.filterlist.push in 'shareable' version. never pushing values array.

javascript arrays angularjs angularjs-scope scope

No comments:

Post a Comment