0
我在AngularJS功能:傳遞變量AngularJS
function TrendChart(){
$scope.data = [];
$scope.datta = [];
TrendChartFactory.get({kpiItem: $scope.selectedKpiItem.key, puItem: $scope.puName},function(data){
$scope.trendValues = data;
console.log($scope.trendValues);
})
getKpiValue($scope.selectedKpiItem.key,$scope.trendValues);
}
,但我想訪問$ scope.trendValues我的功能外像這樣:
function getKpiValue(selectedKPI,trendV) {
for(var i= 0; i< $scope.trendV.length;i++){
console.log($scope.trendV[i][selectedKPI]);
$scope.data.push($scope.trendV[i][selectedKPI]);
}
$scope.datta.push($scope.data);
console.log($scope.datta);
}
但很明顯,我得到它是未定義的錯誤。我怎樣才能解決這個問題 ?
都在同一個控制器兩者的功能? – Deep
是的,它們具有相同的功能 – blaa
當您調用函數getKpiValue時,您傳遞$ scope.trendValues作爲參數。在getKpiValue中,您可以將trendV簡稱爲trendV而不是$ scope.trendV – Thangadurai