AngularJS: Service
by Alberto Naperi Jr.
JavaScript
'use strict';
var app = angular.module('myApp', []);
app.controller('YourCtrl', ['$scope', '$userInteraction', function($scope, $userInteraction) {
$userInteraction.log(Date(), 'Login', 'Some random message.');
console.log($userInteraction.getLog());
}]);
app.service('$userInteraction', [function() {
var userLog = "";
this.log = function (datetime, screen, logMessage) {
userLog.concat(datetime + "\t" + screen + " Screen\t" + logMessage + "\n");
}
this.getLog = function () {
return userLog;
}
this.clearLog = function () {
userLog = "";
}
//return this;
}]);