I am currently working on an Angular application that includes a textarea
:
<textarea id="log_text_area" readonly>{{logger}}</textarea>
In addition, there is a Logger
service designed to update this textarea
.
angular.module('app').factory('Logger', [function(){
var logger = {};
//
// Log writing function
//
logger.log = function(log_area, arguments){
// Get the current date
var date = new Date();
// Initialize log message
var message = '';
// Iterate through the object and build log message
for (var i = 0; i < arguments.length; i++) {
message += arguments[i] + " ";
}
console.log(log_area);
// Check if log area is defined
if (log_area != undefined){
// Create log value
var value = "[" + date + "}] " + message + "\n";
value += log_area;
log_area = value;
}
};
// Return logger object
return logger;
}]);
Now, I want to update my textarea from the controller:
function MyController($scope, Logger) {
$scope.logger = '';
Logger.log($scope.logger, 'Logs Logs Logs');
}
However, the textarea does not update as expected. Can someone guide me on how to update the textarea using an Angular
service?
Thank you.