If you find yourself frequently needing to use the output in the view's console during development, it can be cumbersome to write the function each time.
A more efficient approach is to utilize the built-in angular directive $log
.
Check out a live example on jsfidlle.
var app = angular.module('my-app', [], function() {}).run(function($rootScope,$log){
$rootScope.$log = $log;
});
app.controller('AppController', function($scope) {
$scope.trabajadores = {
csv: {
result: [0, ['e1', 'e2']]
}
};
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="my-app">
<div ng-controller="AppController">
<select ng-model="trabajadores.orderSelected" ng-options="excel for excel in trabajadores.csv.result[1]" ng-change="$log.log('changed '+ trabajadores.orderSelected)">
</select>
</div>
</div>
While this production code may not be ideal for deployment, it is incredibly useful for debugging purposes.
By implementing $log
, you can easily access it in any controller without having to do extra work.