我试图为我的程序实现一种方法来跟踪用户选择和搜索过的过滤器。输入将在文本框中,多个文本框中。我有一个每个选项的文本框(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"。但是当我稍后使用它时(这不是我的预期用例,我只是想确保我可以确定数组的范围并在函数内部调用它)输出是不正确的。实际的预期用例是我将其附加到网址的末尾。
编辑: 这是我的代码的可共享版本:
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:
将我的代码更改为一个数组时,没有" $ scope。"在它的前面,代码工作。但我相信我确实需要" $范围。"它可以使用角度指令。
答案 0 :(得分:0)
问题是您要在“可共享”字段中为$scope.filterList.push
分配字符串值。版。你永远不会将值推入数组。