0

I am a newbie learning Angular. I have created a test page in Aps.net MVC using Angluar, trying to retrieve some data from DB.retrieving data is fine. it happens to be an object of Array. but ng-repeat doesn't show it. My Angular Controller

    (function () {  

    var CompanyController = function ($scope,companyRepository) {

        //another function which runs when http request completes.
        var onGetCompaniesComplete = function (response) {
            console.log(response);
            $scope.companiesList = response;
            alert($scope.companiesList.length);
        };
        // on error

        var onError = function (error) {
            console.log('An error occured while getting companies list');
        };

        $scope.Message = "Hello to the world of Angularjs.";

        //getting companies list.
        companyRepository.get().
        then(onGetCompaniesComplete, onError);

    };
    // registration the controller.
    registrationModule.controller('CompanyController',CompanyController);


}());

companyRepository

    registrationModule.factory('companyRepository', function ($http, $q) {
    return {
        get: function () {
            var deffered = $q.defer();
            $http.get('/CompanyNG/GetCompanies').success(deffered.resolve).error(deffered.reject);
            return deffered.promise;
        }
    }
});

Asp.Net controller action

 public ActionResult Index()
    {
        return View();
    }

    public string GetCompanies()
    {
        var companyModel = repository.Companies;
        //var jsonResult = Json(companyModel, JsonRequestBehavior.AllowGet);
        //return Json(companyModel, JsonRequestBehavior.AllowGet);
        var settings = new JsonSerializerSettings { ContractResolver=new CamelCasePropertyNamesContractResolver() };
        var companies = JsonConvert.SerializeObject(companyModel, Formatting.None, settings);
        return companies;
    }

View

    @section scripts{
    <script src="~/Scripts/Controllers/Repositories/CompanyRepository.js"></script>
    <script src="~/Scripts/Controllers/CompanyController.js"></script>
}
<div ng-controller="CompanyController">
    {{Message}}

    <table>
        <thead>
            <tr>
                <th>
                    Name
                </th>
                <th>
                    Found
                </th>
                <th>
                    Office#
                </th>
                <th>
                    PSEB Registered

                </th>
            </tr>
        </thead>        
        <tbody>
        <tr ng-repeat="company in companiesList"></tr>
        <td>{{company.companyName}}</td>        
        </tbody>
    </table>
</div>

2 Answers 2

1

Like this

<tr ng-repeat="company in companiesList">
    <td>{{company.companyName}}</td>
</tr>
Sign up to request clarification or add additional context in comments.

Comments

0

Guys I think found the cause to the problem. if you look into view. the html isn't defined properly.

<tr ng-repeat="company in companiesList"></tr>
<td>{{company.companyName}}</td> 

Which should be like the following

<tr ng-repeat="company in companiesList">
    <td>{{company.companyName}}</td>
</tr>

It solved the problem and I was able to see the data on the page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.