문제

In Angular Dart, can you mix regular parameters and injected parameters in a class constructor? When I instantiate the class, I get a missing arguments error. For example:

If you have:

class Foo {
  String b;
  Http _http;

  Foo(String this.b, Http this._http);
}

Foo foo = new Foo('beta'); 

//Error missing arguments.

My work around

class Foo {
  String b;
  Http _http;

  Foo(Http this._http);
}

Foo foo = new Foo(); 
foo.b = 'beta';

What I would like:

class Foo {
  String b;
  Http _http;

  Foo(String this.b) {
    //inject an instance of _http here?
  }
}

Foo foo = new Foo('beta'); 
도움이 되었습니까?

해결책

You can pass the injector as a second parameter and let your Foo class' constructor pull the HTTP from the injector
like show in the answer to this question Manual injection in Dart

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top