2016-01-13 20 views
0
var app = angular.module('app', []); 

app.directive('myGridTable', function($http) { 
    return { 
    restrict: 'AE', 
    link: function(scope, element, attrib) { 
     $http.get(attrib.src).success(function(response) { 
     scope.rows = response.data; 
     }); 
     console.log("message from directive"); 
     angular.forEach(scope.rows, function(value, key) { 
     console.log(key); 
     }); 
    } 
    }; 
}); 

回答

2

您正在訪問回調之外的響應。

讓你的循環成功。

嘗試這樣

$http.get(attrib.src).success(function(response) { 
    scope.rows = response.data; 
    console.log("message from directive"); 
    angular.forEach(scope.rows, function(value, key) { 
     console.log(key); 
    }); 
}); 
+0

感謝.....它是我的錯 –

+0

@DebasishDasGupta歡迎您:)不要忘記將其標記爲接受的:) –