javascript - 类型错误 : Cannot read property 'concat' of undefined

标签 javascript angularjs

我的问题是,当我运行我的项目时,它给我一个错误:TypeError: Cannot read property 'concat' of undefined.它不显示请帮助。

app.js

    var Call24 = angular.module("Call24", ["ngResource", "ngRoute"]).
config(function($routeProvider) {
    $routeProvider.
        when('/', { controller: ListCtrl, templateUrl: 'CycleModal.html' }).
        when('/edit/:editId', { controller: EditCtrl, templateUrl: 'details.html' }).

        otherwise({ redirectTo: '/' });

    Call24.factory('cyclesFactory', function ($resource) {
return $resource('/api/Cycles/:id', { id3: '@id3' }, { update: 'PUT' });
});

 var ListCtrl = function ($scope, $location, data,$http) {

$scope.selectTest = null;
$scope.testTest = [];
 $scope.cycle = [];

$http({
    method: 'GET',
    url: '/api/Cycles/',
    data: { CycleID: 1 }
}).success(function (result) {
    $scope.testTest = result;
});

$scope.search = function() {
    data.query({
        offset: $scope.offset,
        limit: $scope.limit
        },
        function(something) {
            $scope.cycle = $scope.cycle.concat(something);
        });
};
   $scope.search();

$scope.show_more = function() {
    $scope.offset += $scope.limit;
    $scope.search();
};

 $scope.reset = function () {
   $scope.limit = 4;
   $scope.offset = 0;
   $scope.cycle = [];
   $scope.search();
 }
 };

html

周期中的周数

                    <div class="col-sm-3">
                        <div class="form-group">
                            <div class="input-group input-group-addon">
                                <label>Cycle number</label>
                                <input ng-model="query" class="form-control" placeholder="search         rep">
                                <!--<div class="input-group-btn">
                                    <button ng-click="reset()" class="btn btn-default"    type="submit"><i class="glyphicon glyphicon-search"></i></button>
                                </div>-->
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-1">
                        <div class="form-group">
                            <div class="input-group input-group-addon">
                                <!--<label>Rep</label>
                                <input ng-model="part" class="form-control" placeholder="search rep">-->
                                <div class="input-group-btn">
                                    <button ng-click="reset()" class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

  <table class="table table-striped table-condensed table-bordered">
    <thead>
    <th>Cycle Id</th>
    <th>Weeks In Cycle</th>
    <th>Cycle Number</th>
    <th>Start Date</th>
    <th>End Date</th>

    </thead>
    <tbody>
        <tr ng-repeat="liss in cycle">
            <td>{{liss.CycleID}}</td>
            <td>{{liss.WeeksInCycle}}</td>
            <td>{{liss.Cycle}}</td>
            <td>{{liss.StartDate}}</td>
            <td>{{liss.EndDate}}</td>

        </tr>
    </tbody>
</table>
<div class="form-actions">

    <button class="btn btn-primary" ng-click="updateSurvey()">
        Ok
    </button>
    <button class="btn btn-danger">
        <a href="#/index.html" style="color: white; text-decoration: none">Cancel</a>
    </button>
</div>

我想显示表格中的列表,但它一直给出我在上面显示的错误。

最佳答案

因为$scope.cycle没有初始化

$scope.cycle = '' or $scope.cycle= [] // as per your requirement

关于javascript - 类型错误 : Cannot read property 'concat' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27900035/

相关文章:

javascript - Unicode RegEx 不匹配外来字符

javascript - $cacheFactory 使用自定义服务

javascript - AngularJS Material 布局 - 弹性问题

angularjs - AngularJS 指令模板可以呈现另一个指令吗?

css - 从页面上的按钮更新页面上的元素 CSS

javascript - 内容可编辑在刷新时丢失其选项卡/新行

javascript - 花式框宽度不适用

javascript - 我可以向cheerio 添加更多jquery 选择器吗? ( Node .js)

javascript - 使用 Angular Material 将 FAB 放在 seam 上

javascript - 访问 JSON 对象详细信息