admin管理员组文章数量:1327059
I am new to Angularjs , I want to display the JSON data from webservice response to in grid form by using ng-grid .My code is here
function TestController($scope, $http) {
alert("test");
$http({
url: 'http://my_Personal_Url',
method: "POST",
data: postData,
headers: {'Content-Type': 'application/jsonp'}
}).success(function (data, status, headers, config) {
$scope.persons = data; //
}).error(function (data, status, headers, config) {
alert("test2");
$scope.status = status;
});
But In the above code the PostData is not defined.my ng-grid scope is like this
$scope.gridOptions = {
data: 'myData',
columnDefs: [
{field: 'DirectLine', displayName: 'DirectLine'},
{field:'Email', displayName:'Email'}
{field:'Employee', displayName:'Employee'}
{field:'Extention', displayName:'Extention'}
{field:'Id', displayName:'Id'}
{field:'PhoneNumber', displayName:'PhoneNumber'}
{field:'Title', displayName:'Title'}
]
};
NOw how can i get the data from json object to myData ? so that i can use ng-grid as
<div ng-controller="TestController">
<div class="gridStyle" ng-grid="gridOptions"></div>
</div>
here the my personal url (it is confidential so i don't want to show ) The above code shows sometimes as postData is not defined and sometimes getting 405 error .
Please explain the problem with the plunker link
I am new to Angularjs , I want to display the JSON data from webservice response to in grid form by using ng-grid .My code is here
function TestController($scope, $http) {
alert("test");
$http({
url: 'http://my_Personal_Url',
method: "POST",
data: postData,
headers: {'Content-Type': 'application/jsonp'}
}).success(function (data, status, headers, config) {
$scope.persons = data; //
}).error(function (data, status, headers, config) {
alert("test2");
$scope.status = status;
});
But In the above code the PostData is not defined.my ng-grid scope is like this
$scope.gridOptions = {
data: 'myData',
columnDefs: [
{field: 'DirectLine', displayName: 'DirectLine'},
{field:'Email', displayName:'Email'}
{field:'Employee', displayName:'Employee'}
{field:'Extention', displayName:'Extention'}
{field:'Id', displayName:'Id'}
{field:'PhoneNumber', displayName:'PhoneNumber'}
{field:'Title', displayName:'Title'}
]
};
NOw how can i get the data from json object to myData ? so that i can use ng-grid as
<div ng-controller="TestController">
<div class="gridStyle" ng-grid="gridOptions"></div>
</div>
here the my personal url (it is confidential so i don't want to show ) The above code shows sometimes as postData is not defined and sometimes getting 405 error .
Please explain the problem with the plunker link
Share Improve this question asked Apr 21, 2014 at 6:50 ShekkarShekkar 2443 gold badges10 silver badges22 bronze badges 2-
How does
myData
look like? – bobthedeveloper Commented Apr 21, 2014 at 7:29 - actually i am in doubt how to generate grid ,in case of myData the grid fields are shown above ,and in the $http syntax unfortunately i used $scope.persons instead of myData which was bind in the controller . – Shekkar Commented Apr 22, 2014 at 9:21
1 Answer
Reset to default 3The 'data' property in ng-grid accepts the name of the data object, in your case the name is "persons" since the response from your HTTP request goes to $scope.persons
.
Example:
$scope.gridOptions = {
data: 'persons',
columnDefs: [
{field: 'DirectLine', displayName: 'DirectLine'},
{field:'Email', displayName:'Email'}
{field:'Employee', displayName:'Employee'}
{field:'Extention', displayName:'Extention'}
{field:'Id', displayName:'Id'}
{field:'PhoneNumber', displayName:'PhoneNumber'}
{field:'Title', displayName:'Title'}
]
};
Live example: http://plnkr.co/edit/UndbtO?p=preview
本文标签: javascripthow to display json data in nggrid in angularjsStack Overflow
版权声明:本文标题:javascript - how to display json data in ng-grid in angularjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742212759a2434015.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论