I have successfully created a news ticker that works well in my codepen example. However, I am encountering an issue with integrating it into my code structure. The error message I am currently receiving is:
Cannot read property 'push' of undefined
Below is a snippet of the controller code causing this issue:
"use strict";
var app = angular.module('portlandApp');
// WEB SERVICE GET REQUEST
var NewsService = function ($http){
this.$http = $http;
}
NewsService.prototype.getarticles = function () {
return this.$http.get('app/data/news.json').then(function (response){
return response.data;
});
};
app.service("newsService", NewsService);
angular
.module('portlandApp')
.controller('newsCtrl', ['$scope', 'newsService', '$location', '$interval', '$timeout', function($scope, newsService, $location, $timeout, $interval) {
var promise = newsService.getarticles();
promise.then(function (data){
$scope.articles = data.news.map(function(item) {
//item.date = moment().format('Do MMMM YYYY');
return item;
});
console.log(data)
});
// AMOUNT OF ARTICLES
$scope.articleLimit = 4;
// NEWS TICKER FUNCTION
$scope.moving = false;
$scope.moveLeft = function() {
$scope.moving = true;
$timeout($scope.switchFirst, 1000);
};
$scope.switchFirst = function () {
$scope.news.push($scope.newsLink.shift());
$scope.moving = false;
$scope.$apply();
};
$interval($scope.moveLeft, 2000);
}]);