0

I have created a small Angular module on my website that (on poge load) calls a list of clubs from a database and should show them on via the view. I am having a problem whereas the controller is not updating itself. The controller variable is showing the correct data but it is not updating the view. Here is my code:

View file:

<div ng-app="clubFilter" ng-cloak class="col-lg-12" ng-controller="clubController"> 
{{clubObj.clubs}}
<div class="col-lg-3" id="clubs-filter-left">
    <form ng-submit="filterClubs()">
        <input type="text" name="location" ng-model="searchTerm" placeholder="Search..." />
        <input type="submit" name="submit" value="Submit" />
    </form>
    <div id="searchInfo" ng-show="(searchTerm != '') || (activityText != '')">
        <span ng-show="searchTerm != ''"><strong>Location:</strong> {{searchTerm}}</span>
        <span ng-show="activityText != ''"><strong>Activity:</strong> {{activityText}}</span>
        <span class=''>(Distance indicated in miles)</span>
    </div>
    <div id="activityInfo" ng-show="activityText != ''">
        <p>Your nearest Leisure Centres with {{activityText}} facilties</p>
    </div>
</div>
<div class="col-lg-9" >     
    <ul class="leisure-centres">            
        <li ng-repeat="club in clubs" ng-show="club.show">              
            <div class="centre">
                <a class="link" ng-href="http://isca01.bigwavemedia.info{{club.link}}">More info</a>
                <a class="link" ng-show="club.distance > 0" ng-href="{club.link}" ng-cloak>{{club.distance}}m</a>           
                <div class="image" ng-show="club.image > 0">
                    <img src="{{image}}" alt="{{club.title}}" />                        
                </div>
                <div class="details">
                    <div class="title">
                        <h3>{{club.title}}</h3>
                    </div>
                    <div class="address">
                        {{club.building}},
                        {{club.street}},
                        {{club.city}},
                        {{club.county}},
                        {{club.postcode}}                           
                    </div>
                    <div class="tel">
                        <strong>Tel: </strong>
                        <a href="tel:{{club.telephone}}" ng-bind="club.telephone"></a>
                    </div>
                    <div class="email">
                        <strong>Email: </strong>
                        <a href="mailto:{{club.email}}" ng-bind="club.email"></a>
                    </div>
                </div>
            </div>
        </li>           
    </ul>
</div>

Controller:

angular.module('clubFilter.controllers', []).
controller('clubController', function($scope, $http, googleMapService, clubService) {

    if(searchTerm == "" && activity == "") {        
        clubService.getClubs().then(function(clubs) {
            $scope.clubs = clubs;
            console.log($scope.clubs);
        });     
    } else if (searchTerm != "" && activity == "") {

    } else if (searchTerm == "" && activity == "") {

    } else if (searchTerm != "" && activity != "") {

    }

Here is the results of the console.log (you can see that there are results and they are correct)

Object { id="1", a_id="["2","6","11","13","14",...8","69","76","84","97"]", title="Ashington Leisure Centre", more...}, Object { id="2", a_id="null", title="Beach Huts", more...}, Object { id="3", a_id="["2","6","11","13","14",...","70","76","84","105"]", title="Blyth Sports Centre",

Can anyone see why the $scope.clubs variable is not binging itself to the ng-repeat in my view? Thanks

1 Answer 1

1

I do not see show anywhere in your club objects…therefore the ng-show="club.show" would be false and prevent the view from displaying your clubs in the ng-repeat.

Instead of:

<li ng-repeat="club in clubs" ng-show="club.show">

try this:

<li ng-repeat="club in clubs">
Sign up to request clarification or add additional context in comments.

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.