本文介绍了配置AngularDart模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试添加一个HttpInterceptor。在AngularJS中,我将写如下:
m.config([$ httpProvider, function($ httpProvider){...}])
但似乎没有配置函数在AngularDart。
配置AngularDart模块的正确方法是什么?
解决方案
HttpInterceptors在AngularDart中的实现略有不同。
main(){
// define你的拦截器
var intercept = new HttpInterceptor();
intercept.request =(HttpResponseConfig requestConfig)=> / * something * /;
intercept.response =(HttpResponse response)=> / * something * /;
intercept.requestError =(dynamic error)=> / * something * /;
intercept.responseError =(dynamic error)=> / * something * /;
//获取HttpInterceptors实例 - 有很多方法可以做到这一点。
Injector injector = ngBootstrap(/ * ... * /);
var interceptors = injector.get(HttpInterceptors);
//注册/添加您的拦截器
interceptors.add(intercept)
}
有关API的更多信息:
I'm trying to add an HttpInterceptor. In AngularJS I would write something like this:
m.config(["$httpProvider", function($httpProvider) {...}])
But it seems like there is no config function in AngularDart.
What is the right way to configure AngularDart modules?
解决方案
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)
}
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模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!