0

I have the following AngularJS controller:

function MemberCtrl($scope){
    $.ajax({
        url: "/getmembers",
        type: "get",
        success:function(data){
            $scope.members = data.member_list;
            console.log($scope.members); //works fine
        } 
    });
}

My view looks like this:

 <div ng-controller="MemberCtrl">
    <ul>
       <li ng-repeat="member in members">
        <span>{{member.name}}</span>
       </li>
    </ul>
 </div>

As you can see in the first block of code I make a simple AJAX GET to my resource which returns fine in my console.log(). However, nothing changes in my view. I'm guessing this is an issue with the success: being async, but I'm not sure how to fix that.

Thanks for any help!

Carpetfizz

1

1 Answer 1

2

You should use the built in $http service.

function MemberCtrl( $scope, $http ) {

    $http.get('/getmembers')
    .success(function( data, status, headers, config ) {
        $scope.members = data.member_list;
    });

}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this works perfectly, I will accept in 6 mins when I can.

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.