Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm pretty new to AngularJS.

This is my HTML:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html ng-app="Resource">
<head runat="server">

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>

    <script src="JS/controller.js" type="text/javascript"></script>

    <title></title>
</head>
<body>
    <div ng-controller="ResourcesCtrl">
        <form id="form1" runat="server">
        <div>
            <table>
                <thead>
                    <tr>
                        <th>
                            Name
                        </th>
                        <th>
                            Value
                        </th>
                        <th>
                            Comment
                        </th>
                        <th>
                            Action
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="resource in resources">
                        <td>
                            {{resource.KeyName}}
                        </td>
                        <td>
                            {{resource.Text}}
                        </td>
                        <td>
                            {{resource.Comment}}
                        </td>
                        <td>
                            <span>Update</span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        </form>
    </div>
</body>
</html>

This is my JS:

var myModule = angular.module('Resource', []).factory('ResourceData', function($http) {
    return {
        getResources: function(prmLangId) {
            //return the promise directly.
            return $http.get('Default.aspx/GetResources', { langId: prmLangId }).
                       then(function(result) {
                           //resolve the promise as the data
                           console.log(result);
                           return result.data;
                       });
        }
    }
});

myModule.config(function($httpProvider) {

            $httpProvider.defaults.headers.get = {};

            $httpProvider.defaults.headers.get["Content-Type"] = "application/json; charset=utf-8";

        });

function ResourcesCtrl($scope, ResourceData) {
    $scope.resources = ResourceData.getResources(1033);
}

And this is the server method:

 [WebMethod]
    public static string GetResources(int langId)
    {
        ResourcesManagerBL resBl = new ResourcesManagerBL(langId);
        var resources = resBl.GetResourcesForLanguage(langId);
        return Json.ToJson(resources);
    }

The result is many blank rows (as the number of the resources), What I'm doing wrong, in the console the data look OK.

The result is something like this:

enter image description here

share|improve this question
    
Change the parm datatype int to string – Ramesh Rajendran Sep 29 '13 at 7:40
    
@RameshRajendran, it did not help.. – ronen Sep 29 '13 at 7:44
1  
If result contains html instead of json string, then the method is not correctly being hit. Try to hit the url Default.aspx/GetResources/1033 with some tools like fiddler or Postman (chrome tool) by setting appropriate headers and see if you get json result. – Chandermani Sep 29 '13 at 7:52
    
Can you show the result? – Davin Tryon Sep 29 '13 at 8:44
    
@Chandermani, I was able to make the call, and the data returns fine but I still present blank rows (only with the static "Update" string for each row) – ronen Sep 29 '13 at 8:49

web method can return the actual type (like List) , and module should be populated with result.data.d

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.