相关疑难解决方法(0)

NG2 RC5:不推荐使用HTTP_PROVIDERS

因此,在Angular2的RC5版本中,他们弃用HTTP_PROVIDERS并引入了HttpModule.对于我的应用程序代码,这工作正常,但我正在努力在我的Jasmine测试中进行更改.

这是我目前在我的规范中所做的事情,但由于不推荐使用HTTP_PROVIDERS,我现在应该做些什么呢?有什么我需要提供而不是HTTP_PROVIDERS?在RC5世界中这样做的正确方法是什么?

beforeEach(() => {
  reflectiveInjector = ReflectiveInjector.resolveAndCreate([
    HTTP_PROVIDERS,
    ...
  ]);

  //other code here...
});

it("should....", () => { ... });
Run Code Online (Sandbox Code Playgroud)

angular2-testing angular

13
推荐指数
1
解决办法
9389
查看次数

以角度2手动注入Http

我创建了一个基本模型,其中我有所有常用函数来获取数据并发布或放置数据.实际上服务是什么角度,但我不想要一个服务.不,我打算做的是基础模型将扩展到我的系统中的所有模块,每个模块都有其基本端点来从API获取数据.现在问题如果我在基本模型中注入Http服务并且用户模型扩展了Base模型,现在要创建基本模型的对象,我需要传递Http的对象,这是我无法解决的.

如果您需要更多支持来回答这个问题,请告诉我.

export class BaseModel {
constructor (http: Http) {}

fetch() {
let params = {
            "includes": this.includes,
            "page": page,
            "filters" : this.filters,
            "order" : this.orderDirection + this.orderColumn
        };

        return this.api.get("/"+this.endpoint, params)
            .map(
                (response: any) => {
                    let total = response.meta.total;
                    let current = response.meta.current;

                    let min = current - 5;
                    let max = current + 5;

                    if (min < 1) {
                        min = 1;
                    }

                    if (max > total) {
                        max = total;
                    }
                    else if (max < 10) …
Run Code Online (Sandbox Code Playgroud)

angular

8
推荐指数
2
解决办法
3500
查看次数

标签 统计

angular ×2

angular2-testing ×1