Upgraded to AngularDart 0.13.0 and getting errors

2019-07-17 03:03发布

问题:

I upgraded to AngularDart 0.13.0 and I am receiving the errors below. What is the correct way to initialize the RoutingModule with the new di package 2.0.1?

In main.dart I have:

class RoutingModule extends Module {
  RoutingModule() {
    bind(RouteInitializerFn, toValue: myRouteInitializer);
    bind(NgRoutingUsePushState,
        toFactory: (_) => new NgRoutingUsePushState.value(false));
  }
}

Let me know if you think any other Modules would be relevant. The rest are just simple bind(Component); statements.

I am receiving the following 2 errors:

bind(RouteProvider): Inject list without toFactory is deprecated. Use `toInstanceOf: Type|Key` instead. Called from:
#0      Binding.bind (package:di/src/module.dart:33:11)
#1      DirectiveInjector.bind (package:angular/core_dom/directive_injector.dart:163:23)
#2      module (package:angular/routing/ng_view.dart:60:21)
#3      ElementBinder.bind (package:angular/core_dom/element_binder.dart:285:35)
#4      TaggingViewFactory._bindTagged (package:angular/core_dom/tagging_view_factory.dart:95:36)
#5      TaggingViewFactory._link (package:angular/core_dom/tagging_view_factory.dart:143:24)
#6      TaggingViewFactory.call (package:angular/core_dom/tagging_view_factory.dart:72:12)
#7      Application.run.<anonymous closure>.<anonymous closure> (package:angular/application.dart:183:22)
#8      _rootRunUnary (dart:async/zone.dart:730)
#9      _ZoneDelegate.runUnary (dart:async/zone.dart:462)
#10     _onRunUnary.<anonymous closure> (package:angular/core/zone.dart:116:63)
#11     VmTurnZone._onRunBase (package:angular/core/zone.dart:99:16)
#12     _onRunUnary (package:angular/core/zone.dart:116:17)
#13     _ZoneDelegate.runUnary (dart:async/zone.dart:462)
#14     _CustomizedZone.runUnary (dart:async/zone.dart:667)
#15     _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:488)
#16     _Future._propagateToListeners (dart:async/future_impl.dart:571)
#17     _Future._completeWithValue (dart:async/future_impl.dart:331)
#18     _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:393)
#19     _rootRun (dart:async/zone.dart:723)
#20     _ZoneDelegate.run (dart:async/zone.dart:453)
#21     _onScheduleMicrotask.<anonymous closure> (package:angular/core/zone.dart:119:43)
#22     VmTurnZone._finishTurn (package:angular/core/zone.dart:146:34)
#23     VmTurnZone._onRunBase (package:angular/core/zone.dart:106:43)
#24     _onRun (package:angular/core/zone.dart:112:17)
#25     _ZoneDelegate.run (dart:async/zone.dart:453)
#26     _CustomizedZone.run (dart:async/zone.dart:663)
#27     VmTurnZone.run (package:angular/core/zone.dart:235:40)
#28     Application.run (package:angular/application.dart:171:20)
#29     main (http://localhost/main.dart:52:11)
Closure call with mismatched arguments: function 'RoutingModule.RoutingModule.<anonymous closure>'

NoSuchMethodError: incorrect number of arguments passed to method named 'RoutingModule.RoutingModule.<anonymous closure>'
Receiver: Closure: (dynamic) => dynamic
Tried calling: RoutingModule.RoutingModule.<anonymous closure>()
Found: RoutingModule.RoutingModule.<anonymous closure>(_@0x14ac1f93)

STACKTRACE:
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1      ModuleInjector.getByKey (package:di/src/injector.dart:162:48)
#2      ModuleInjector.getByKey (package:di/src/injector.dart:185:7)
#3      ModuleInjector.getByKey (package:di/src/injector.dart:145:38)
#4      ModuleInjector.getByKey (package:di/src/injector.dart:185:7)
#5      DirectiveInjector._getByKey (package:angular/core_dom/directive_injector.dart:209:72)
#6      DirectiveInjector._new (package:angular/core_dom/directive_injector.dart:287:39)
#7      DirectiveInjector._getDirectiveByKey (package:angular/core_dom/directive_injector.dart:216:94)
#8      DirectiveInjector._getByKey (package:angular/core_dom/directive_injector.dart:211:44)
#9      DirectiveInjector.getByKey (package:angular/core_dom/directive_injector.dart:198:23)
#10     DirectiveInjector.getByKey (package:angular/core_dom/directive_injector.dart:199:7)
#11     DirectiveInjector.getByKey (package:angular/core_dom/directive_injector.dart:199:7)
#12     ElementBinder._link (package:angular/core_dom/element_binder.dart:207:49)
#13     ElementBinder.bind (package:angular/core_dom/element_binder.dart:298:10)
#14     TaggingViewFactory._bindTagged (package:angular/core_dom/tagging_view_factory.dart:95:36)
#15     TaggingViewFactory._link (package:angular/core_dom/tagging_view_factory.dart:143:24)
#16     TaggingViewFactory.call (package:angular/core_dom/tagging_view_factory.dart:72:12)
#17     TaggingViewFactory.call (package:angular/core_dom/tagging_view_factory.dart:74:7)
#18     TaggingViewFactory.call (package:angular/core_dom/tagging_view_factory.dart:74:7)
#19     Application.run.<anonymous closure>.<anonymous closure> (package:angular/application.dart:183:22)
#20     _rootRunUnary (dart:async/zone.dart:730)
#21     _ZoneDelegate.runUnary (dart:async/zone.dart:462)
#22     _onRunUnary.<anonymous closure> (package:angular/core/zone.dart:116:63)
#23     VmTurnZone._onRunBase (package:angular/core/zone.dart:99:16)
#24     _onRunUnary (package:angular/core/zone.dart:116:17)
#25     _ZoneDelegate.runUnary (dart:async/zone.dart:462)
#26     _CustomizedZone.runUnary (dart:async/zone.dart:667)
#27     _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:488)
#28     _Future._propagateToListeners (dart:async/future_impl.dart:571)
#29     _Future._completeWithValue (dart:async/future_impl.dart:331)
#30     _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:393)
#31     _rootRun (dart:async/zone.dart:723)
#32     _ZoneDelegate.run (dart:async/zone.dart:453)
#33     _onScheduleMicrotask.<anonymous closure> (package:angular/core/zone.dart:119:43)
#34     VmTurnZone._finishTurn (package:angular/core/zone.dart:146:34)
#35     VmTurnZone._onRunBase (package:angular/core/zone.dart:106:43)
#36     _onRun (package:angular/core/zone.dart:112:17)
#37     _ZoneDelegate.run (dart:async/zone.dart:453)
#38     _CustomizedZone.run (dart:async/zone.dart:663)
#39     VmTurnZone.run (package:angular/core/zone.dart:235:40)
#40     Application.run (package:angular/application.dart:171:20)
#41     main (http://localhost/main.dart:52:11)

EDIT:

I changed my main function to:

void main() {
  applicationFactory()
      .run();
}

and I am still getting the bind(RouteProvider) error.

The Closure call with mismatched arguments error goes away if I comment out the bind(NgRoutingUsePushState, ...) line.

回答1:

Inject list without toFactory is deprecated. Use toInstanceOf: Type|Key instead

I guess toInstanceOf isn't appropriate because it takes a type instead of an instance. I would try toValue instead of toFactory



回答2:

For the mismatched arguments error, you have to remove the _ parameter in the anonymous func:

bind(NgRoutingUsePushState, toFactory: () => new NgRoutingUsePushState.value(false));

I'm still investigating the other issue, which I also have. I'll let you know when I find it.