本文介绍了配置 AngularDart 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试添加一个 HttpInterceptor.在 AngularJS 中,我会这样写:
I'm trying to add an HttpInterceptor. In AngularJS I would write something like this:
m.config(["$httpProvider", function($httpProvider) {...}])
但是好像 AngularDart 中没有配置功能.
But it seems like there is no config function in AngularDart.
配置 AngularDart 模块的正确方法是什么?
What is the right way to configure AngularDart modules?
推荐答案
HttpInterceptors 在 AngularDart 中的实现略有不同.
HttpInterceptors are implemented slightly differently in AngularDart.
main() {
// define your interceptor
var intercept = new HttpInterceptor();
intercept.request = (HttpResponseConfig requestConfig) => /* something */;
intercept.response = (HttpResponse response) => /* something */;
intercept.requestError = (dynamic error) => /* something */;
intercept.responseError = (dynamic error) => /* something */;
// get hold of the HttpInterceptors instance -- there are many ways to do this.
Injector injector = ngBootstrap(/* ... */);
var interceptors = injector.get(HttpInterceptors);
// register/add your interceptor
interceptors.add(intercept)
}
有关 API 的更多信息:
More info on the API:
http://ci.angularjs.org/view/Dart/job/angular.dart-master/javadoc/angular.core.dom/HttpInterceptors.htmlhttp://ci.angularjs.org/view/Dart/job/angular.dart-master/javadoc/angular.core.dom/HttpInterceptor.html
这篇关于配置 AngularDart 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!