Tuesday, 15 April 2014

angularjs - ng-repeat parsing every character of json -



angularjs - ng-repeat parsing every character of json -

still trying track downwards why cannot display json info asp.net webmethod won't display in table using ng-repeat - i've gotten point looks there issue json don't see problem table server json - added index column , seems add together row per character ??

here screenshot of info - there json info server , manually created angular collection looks json data

thanks insight

<%@ page language="c#" autoeventwireup="true" codebehind="test1.aspx.cs" inherits="sampleangularjs.test1" %> <!doctype html> <html > <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script> </head> <body ng-app="codeapp"> <div ng-controller="codecontroller" > <button ng-click="doclick(item, $event)">send ajax request</button> <br /> info server: {{codes}} <br /> info manually built collection: {{fields}} <br /> <h3>and here if homecoming promise returned $http.get():</h3> <pre>{{codes | json}}</pre> <br /> <h3>manually built angular collection table</h3> <table> <tr> <th>code</th> <th>desc</th> </tr> <tr ng-repeat="code in fields"> <td>{{code.code}}</td> <td>{{code.desc}}</td> </tr> </table> <br /> <h3>server json table</h3> <table> <tr> <th>row</th> <th>code</th> <th>desc</th> </tr> <tr ng-repeat="code in codes track $index"> <td>({{$index + 1}}) </td> <td>{{code.code}}</td> <td>{{code.desc}}</td> </tr> </table> </div> <script> angular.module("codeapp", []) .controller("codecontroller", function ($scope, $http) { $scope.fields = [{ code: "aaa", desc: "aaa, desc" }, { code: "bbb", desc: "bbb, desc" }]; $scope.codes = []; $scope.doclick = function (item, event){ $http.post('test1.aspx/getallcodes', { data: {} }) .success(function (data, status, headers, config) { $scope.codes = data.d; }) .error(function (data, status, headers, config) { $scope.status = status; }); } }) .config(function ($httpprovider) { $httpprovider.defaults.headers.post = {}; $httpprovider.defaults.headers.post["content-type"] = "application/json; charset=utf-8"; }); </script> </body> </html>

you're getting string server , ng-repeat on string gives each character. seek parsing see if works, check out request , response headers see why isn't sending info application/json:

.success(function (data, status, headers, config) { $scope.codes = json.parse(data.d); })

angularjs

No comments:

Post a Comment