0

while i am trying to display my data in html using ng-repeat its not displaying. I am trying to create rows dynamically. But the list is not getting displayed.

This is my controller:

app.controller('SearchBusController',['$scope','$sessionStorage','$http','$state',function($scope,$sessionStorage,$http,$state){
    var a="http://localhost:8080/business/allbusiness";
    $scope.BusinessList=[];
            $.ajax({
    type:'GET',
    url:a,

    success:function(data){

    $scope.BusinessList=data;   
    console.log(data)
    },
    error:function(data){
        //alert("unsuccessfull");
        },  
    dataType:"json",
    contentType:"application/json",
});



    }]);

This is my html:

<div ng-app="app" ng-controller="SearchBusController">
    <table class="table1" cellspacing="0px" border="1"  width="60%;" style="background:white;">
    <tr ng-repeat="business in BusinessList">
    <td width="13%">
    <img src="images/welcome.jpg" style= "width:100%;" align="left">
    </td>
   <td colspan="2">
   <a href="">
    <p><span><h3 style="color:white;">{{business.BusinessDTO.company_name}}</h3></p></span></a>
    <a href=""> 
    <p><span><h3>{{business.BusinessDTO.address}}</h3></p></span></a>
    </td>
    </tr>
<table>
</div>

I am getting list in $scope.BusinessList which is

{"businessList":[{"BusinessDTO":{"businessId":1,"company_name":"Zafin","about_company":"asdasd"}},{"BusinessDTO":{"businessId":2,"company_name":"aaa","about_company":"hgfh"}}]}

any help??

3
  • use $http service to make API call instead of $.ajax, it will help you to keep UI in sync by running digest cycle., Commented Apr 4, 2017 at 5:36
  • Yes use $http instead of $ ajax because when you use $ ajax the change happens out of the scope of angular an ugly way would be to call $scope.$apply(); inside your success callback after $scope.BusinessList=data; to manually fire apply but suggest you to use $http Commented Apr 4, 2017 at 5:38
  • but I need $.ajax Commented Apr 4, 2017 at 5:49

2 Answers 2

1

Just try by updating your list assignment as below.

Replace following

$scope.BusinessList=data;   

With

$scope.BusinessList=data.businessList;   
Sign up to request clarification or add additional context in comments.

Comments

0

You can try to add $scope.$apply() after $scope.BusinessList=data.

Also please check your json objects. Your json isn't array. So you cannot use ng-repeat. It must be BusinessList.businessList.

{
      "businessList": [{
          "BusinessDTO": {
              "businessId": 1,
              "company_name": "Zafin",
              "about_company": "asdasd"
          }
      }, {
          "BusinessDTO": {
              "businessId": 2,
              "company_name": "aaa",
              "about_company": "hgfh"
          }
      }]
  }

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.