我升级到AngularDart 0.13.0,我收到以下错误。使用新的di
包2.0.1初始化RoutingModule的正确方法是什么?
在main.dart
我有:
class RoutingModule extends Module {
RoutingModule() {
bind(RouteInitializerFn, toValue: myRouteInitializer);
bind(NgRoutingUsePushState,
toFactory: (_) => new NgRoutingUsePushState.value(false));
}
}
如果您认为任何其他模块具有相关性,请告诉我。其余的只是简单的bind(Component);
陈述。
我收到以下2个错误:
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)
我将主要功能改为:
void main() {
applicationFactory()
.run();
}
我仍然收到bind(RouteProvider)
错误。
如果我注释掉Closure call with mismatched arguments
行,bind(NgRoutingUsePushState, ...)
错误就会消失。
答案 0 :(得分:1)
不推荐使用不带toFactory的注入列表。请改用
toInstanceOf: Type|Key
我猜toInstanceOf
不合适,因为它需要一个类型而不是一个实例。我会尝试toValue
而不是toFactory
答案 1 :(得分:0)
对于不匹配的参数错误,您必须删除匿名func中的_参数:
bind(NgRoutingUsePushState,toFactory :()=&gt; new NgRoutingUsePushState.value(false));
我还在调查另一个问题,我也有。当我找到它时,我会通知您。