角度控制器变量未显示

时间:2014-10-03 09:08:43

标签: angularjs

我在我的一个网站上构建了一个小的Angular组件,我遇到了一些问题。 我为我的应用程序定义了一个控制器,但视图没有从控制器中提取任何变量或函数,我不知道为什么。 这是我的代码:

这是我定义控制器的文件:

angular.module('clubFilter.controllers', []).
controller('clubController', function($scope, $http, googleMapService) {
    $scope.clubsJSON = JSONItems;
    $scope.clubs = $scope.clubsJSON;
    if(searchTerm == "" && activity == "") {            
        $scope.clubs = $scope.clubsJSON;    
        console.log($scope.clubs);
    } else if (searchTerm != "" && activity == "") {

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

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

    }
    ........

这是我的角度应用文件:

var clubFilter = angular.module("clubFilter", [
'clubFilter.controllers',
'clubFilter.services'

]);

这是我的HTML视图:

<div ng-app="clubFilter" ng-cloak class="col-lg-12" ng-controller="clubController">
<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>

当页面加载时,$ scope.clubs对象应该循环播放,然后在视图中的ng-repeat中显示。这似乎并没有发生,有谁能看出为什么这不起作用?我检查了对象的结构,它很好,之前一直在工作。 感谢

编辑添加JSONitems对象结构:

[
Object { 
    id="1", 
    title="Ashington Leisure Centre", 
    description="<p>Ashington Leisure Cen...ase give us a call.</p>", more...}, 
Object { 
    id="2", 
    title="Beach Huts", 
    description="<p>A trip to the beautif...ings - 01670 542222</p>", more...}, 
Object { 
    ........

2 个答案:

答案 0 :(得分:1)

//app
angular.module('clubFilter', ['clubFilterControllers'])

//controller
clubFilterControllers.controller('viewController', ['$scope', '$http', 'googleMapService', 
   function($scope, $http, googleMapService){
   /* logic here */
}])

尝试定义那样的控制器。

答案 1 :(得分:0)

您为控制器设置了别名但未使用别名来访问数据

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