1
AngularJSでグラフをレンダリングします。関数はAngularJSで未定義を返します
サービスTrendChartFactory
は、入力として2つのパラメータを持つデータの取得要求を出します。
は今、私の問題は、私は私はそれが未定義を返すget要求から受信したデータを利用した機能getValue()
を呼び出すときことです。
この問題を解決するにはどうすればよいですか?
ありがとうございます。
angular.module('App')
.directive('Trend',function(){
return {
restrict: 'E',
templateUrl: 'app/trend/trend.html',
scope: {
card: '=',
puName: '<',
selectedItem: '<'
},
controller: function($scope, $rootScope, $filter, TrendChartFactory) {
$scope.$watch('selectedItem', function() {
console.log($scope.selectedItem);
console.log("ChangedSelected");
TrendChart();
}, true);
$scope.$watch('puName', function(){
console.log($scope.puName);
console.log("ChangedpuName");
TrendChart();
},true);
$scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
function getValue(selectedV,trendV) {
for(var i= 0; i< trendV.length;i++) {
console.log(trendV[i][selectedV]);
$scope.data.push(trendV[i][selectedV]);
}
$scope.datta.push($scope.data);
console.log($scope.datta);
}
function TrendChart(){
$scope.data = [];
$scope.datta = [];
TrendChartFactory.get({
Item: $scope.selectedItem.key,
puItem: $scope.puName},function(data){
$scope.trendValues = data;
console.log($scope.trendValues);
});
getValue($scope.selectedItem.key,$scope.trendValues);
}
},
controllerAs: "TrendCtrl"
};
})
getValueの代わりに$ scope.getValueを追加する必要があります – user2323308