I am facing a problem in pushing data value to a JSON which is in service. I have less idea of pushing data to service in AngularJS.
Example I have created a function to show year and time in Controller:-
appName.controller('uController', function ($scope,ConsoleService) {
$scope.showPushData = function(){
$scope.date = new Date();
console.log($scope.date);
$scope.year = $scope.date.getFullYear();
console.log($scope.year);
$scope.time = $scope.date.getTime();
console.log($scope.time);
$scope.ConsoleService.consoleList.year.push($scope.year);
}
})
And in my service I have :-
appName.service('ConsoleService', function ($http) {
this.getInfo = function() {
var consoleList = [{
"year" : "",
"time" :""
}]
}
})
I want to push $scope.year
value from controller to "year" : ""
in service. How can I call service to controller fro this ?
in the bellow code can stored the array .But display in the html page