?
本文檔使用 php中文網(wǎng)手冊 發(fā)布
Simple service for logging. Default implementation safely writes the message into the browser's console (if present).
The main purpose of this service is to simplify debugging and troubleshooting.
The default is to log debug
messages. You can use ng.$logProvider#debugEnabled to change this.
$window
log();
輸出一條日志信息
info();
輸出一條提示信息
warn();
輸出一條警告信息
error();
輸出一條錯(cuò)誤信息
debug();
輸出一條調(diào)試信息
angular.module('logExample', [])
.controller('LogController', ['$scope', '$log', Function($scope, $log) {
$scope.$log = $log;
$scope.message = 'Hello World!';
}]);
<div ng-controller="LogController">
<p>Reload this page with open console, enter text and hit the log button...</p>
Message:
<input Type="text" ng-model="message"/>
<button ng-click="$log.log(message)">log</button>
<button ng-click="$log.warn(message)">warn</button>
<button ng-click="$log.info(message)">info</button>
<button ng-click="$log.error(message)">error</button></div>