TypeError: Cannot read property 'concat' of undefined

My problem is that when i run my project it gives me an error that says: TypeError: Cannot read property 'concat' of undefined. it does not display please help.

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

Weeks in Cycle

 <div> <div> <div> <label>Cycle number</label> <input ng-model="query" placeholder="search rep"> <!--<div> <button ng-click="reset()" type="submit"><i></i></button> </div>--> </div> </div> </div> <div> <div> <div> <!--<label>Rep</label> <input ng-model="part" placeholder="search rep">--> <div> <button ng-click="reset()" type="submit"><i></i></button> </div> </div> </div> </div> </div> </div> </div> </form> <table> <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> <button ng-click="updateSurvey()"> Ok </button> <button> <a href="#/index.html">Cancel</a> </button> </div> 

I want to display the list from a table but it keeps giving the error i have shown above.

2

2 Answers

Because $scope.cycle is not initialized

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

seems like you didn't declare the $scope.cycle before its use, javascript try to invoke concat() of $scope.cycle variable but still there is no variable called $scope.cycle. so invoking concat() of a undefined variable cause a error.

if you try to concat two arrays then

try to add $scope.cycle = [] top of the controller

if you try to concat two Strings then

try to add $scope.cycle = '' top of the controller

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like