是否有一种在离子移动应用程序上显示错误消息的标准方法 . 从文档中我找不到任何与显示错误消息相关的信息 .
提到的文件:http://ionicframework.com/docs/components/
考虑您要将所有HTTP错误发送到Modal,您可以使用 $provide decorator "$exceptionHandler" 覆盖异常:
$provide decorator "$exceptionHandler"
$provide.decorator("$exceptionHandler", function($delegate, $injector) { return function(exception, cause) { /* here you can do what u want */ });
要发送到本机代码甚至是Crashlytics(报告服务器),请使用Cordova网桥:
app.config(function($provide) { $provide.decorator("$exceptionHandler", function($delegate, $injector) { return function(exception, cause) { if (false) { //(appState !== "...") { // We want to only send the error in this case $delegate(exception, cause); } else { //appState == null; var MyCordovaService = $injector.get("MyCordovaService"); console.debug({reason: exception, message: exception.message, stack: exception.stack}); var data = { message: "Exception: " + exception.message, stack: exception.stack || "none" }; MyCordovaService.reportClientError(data).then(function(data) { console.debug('reportClientError success', data); }, function(error) { console.debug('reportClientError fail!', error); }); //} // Call The original Angular Exception Handler $delegate(exception, cause); } }; }); });
Codepan中的演示
希望它会有所帮助,
1 回答
考虑您要将所有HTTP错误发送到Modal,您可以使用
$provide decorator "$exceptionHandler"
覆盖异常:要发送到本机代码甚至是Crashlytics(报告服务器),请使用Cordova网桥:
Codepan中的演示
希望它会有所帮助,