我有一个函数,我认为它被dart2js丢弃,因为它只用在AngularDart NgCallback中,如下所示:
<my-component myCallback="myController.onLineupPositionClick()">
</my-component>
因此,myCallback从我的组件中公开,如下所示:
@NgCallback('myCallback')
Function myCallback;
在myController中,该方法只是一种常规方法:
void onLineupPositionClick() {
print("HELLO");
}
代码在Chromium VM中运行,但在使用&#34; pub build&#34;在Chrome或Firefox中。异常消息是:
"No getter for 'onLineupPositionClick'.
我已经验证过,如果我在ng-click中使用该方法,它可以工作:
<my-component ng-click="myController.onLineupPositionClick()" myCallback="myController.onLineupPositionClick()">
</my-component>
我敢打赌,dart2js正在放弃该方法,因为它无法看到该角色将来会使用它。 ng-click以某种方式阻止了dart2js丢弃该方法......但是NgCallback没有做到这一点,我不明白为什么。
我是对的吗?什么是最好的解决方案?
编辑: 这是我得到的例外:
"No getter for 'onLineupPositionClick'.
STACKTRACE:
.wrapException<@http://localhost:8080/main.dart.js:3036:5
.StaticClosureMap.lookupGetter$1<@http://localhost:8080/main.dart.js:11413:9
.StaticClosureMap.lookupFunction$2<@http://localhost:8080/main.dart.js:11427:7
.DynamicParserBackend.newCallMember$3<@http://localhost:8080/main.dart.js:9629:7
.DynamicParserImpl.parseAccessOrCallMember$0<@http://localhost:8080/main.dart.js:9898:13
.DynamicParserImpl.parsePrefix$0<@http://localhost:8080/main.dart.js:9887:9
.DynamicParserImpl.parseMultiplicative$0<@http://localhost:8080/main.dart.js:9838:7
.DynamicParserImpl.parseAdditive$0<@http://localhost:8080/main.dart.js:9819:7
.DynamicParserImpl.parseRelational$0<@http://localhost:8080/main.dart.js:9788:7
.DynamicParserImpl.parseEquality$0<@http://localhost:8080/main.dart.js:9769:7
.DynamicParserImpl.parseLogicalAnd$0<@http://localhost:8080/main.dart.js:9757:7
.DynamicParserImpl.parseLogicalOr$0<@http://localhost:8080/main.dart.js:9745:7
.DynamicParserImpl.parseConditional$0<@http://localhost:8080/main.dart.js:9729:7
.DynamicParserImpl.parseExpression$0<@http://localhost:8080/main.dart.js:9705:7
.DynamicParserImpl.parseFormatter$0<@http://localhost:8080/main.dart.js:9690:7
.DynamicParserImpl.parseChain$0<@http://localhost:8080/main.dart.js:9677:9
.DynamicParser_call_closure.call$0<@http://localhost:8080/main.dart.js:9472:7
._LinkedHashMap.putIfAbsent$2<@http://localhost:8080/main.dart.js:26121:7
.DynamicParser.call$1<@http://localhost:8080/main.dart.js:9457:7
.ElementBinder._dom_internal$_parser$1@http://localhost:8080/main.dart.js:5995:7
.ElementBinder__createAttrMappings_closure.call$1<@http://localhost:8080/main.dart.js:6245:11
.IterableMixinWorkaround_forEach<@http://localhost:8080/main.dart.js:20146:7
.ElementBinder._createAttrMappings$6<@http://localhost:8080/main.dart.js:6033:7
.ElementBinder__link_closure.call$1<@http://localhost:8080/main.dart.js:6319:9
.IterableMixinWorkaround_forEach<@http://localhost:8080/main.dart.js:20146:7
.ElementBinder._link$5<@http://localhost:8080/main.dart.js:6043:7
.ElementBinder.bind$3<@http://localhost:8080/main.dart.js:6121:7
.TaggingViewFactory._bindTagged$6<@http://localhost:8080/main.dart.js:8523:7
.TaggingViewFactory._link$3<@http://localhost:8080/main.dart.js:8554:13
.TaggingViewFactory.call$2<@http://localhost:8080/main.dart.js:8500:9
.TaggingViewFactory.call$2<@http://localhost:8080/main.dart.js:8508:7
.TranscludingComponentFactory_call__closure.call$1<@http://localhost:8080/main.dart.js:8742:7
._rootRunUnary<@http://localhost:8080/main.dart.js:21821:7
._ZoneDelegate.runUnary$3<@http://localhost:8080/main.dart.js:24846:7
.VmTurnZone__onRunUnary_closure.call$0<@http://localhost:8080/main.dart.js:13348:7
.VmTurnZone._onRunBase$4<@http://localhost:8080/main.dart.js:13241:9
.VmTurnZone._onRunUnary$5<@http://localhost:8080/main.dart.js:13261:7
anonymous/<@http://localhost:8080/main.dart.js line 3346 > Function:1:28
._ZoneDelegate.runUnary$3<@http://localhost:8080/main.dart.js:24846:7
._CustomizedZone.runUnary$2<@http://localhost:8080/main.dart.js:25061:7
._Future__propagateToListeners_handleValueCallback.call$0<@http://localhost:8080/main.dart.js:22844:9
._Future.static._Future__propagateToListeners<@http://localhost:8080/main.dart.js:22727:17
._Future._completeWithValue$1<@http://localhost:8080/main.dart.js:22542:7
._Future__asyncComplete_closure0.call$0<@http://localhost:8080/main.dart.js:22823:7
._rootRun<@http://localhost:8080/main.dart.js:21803:7
._ZoneDelegate.run$2<@http://localhost:8080/main.dart.js:24837:7
.VmTurnZone__onScheduleMicrotask_closure.call$0<@http://localhost:8080/main.dart.js:13356:7
.VmTurnZone._finishTurn$2<@http://localhost:8080/main.dart.js:13286:13
.VmTurnZone._onRunBase$4<@http://localhost:8080/main.dart.js:13253:11
.VmTurnZone._onRunUnary$5<@http://localhost:8080/main.dart.js:13261:7
anonymous/<@http://localhost:8080/main.dart.js line 3346 > Function:1:28
._ZoneDelegate.runUnary$3<@http://localhost:8080/main.dart.js:24846:7
._CustomizedZone.runUnary$2<@http://localhost:8080/main.dart.js:25061:7
._BaseZone.runUnaryGuarded$2<@http://localhost:8080/main.dart.js:24947:9
._BaseZone_bindUnaryCallback_closure.call$1<@http://localhost:8080/main.dart.js:25018:7
.invokeClosure_closure0.call$0<@http://localhost:8080/main.dart.js:4701:7
._IsolateContext.eval$1<@http://localhost:8080/main.dart.js:1793:9
._callInIsolate<@http://localhost:8080/main.dart.js:1269:1
.invokeClosure<@http://localhost:8080/main.dart.js:3171:7
.convertDartClosureToJS</$function</<@http://localhost:8080/main.dart.js:3191:9
"
当然,如果我删除&#34; myCallback&#34;一切都有效。我使用的是Angular 0.12,Dart 1.5.1。
答案 0 :(得分:0)
如果你想阻止某些功能被&#34; Tree sha away掉&#34;你可以:
将此函数分配给代码中的某个变量,例如,调用.toString()
或者您可以将其标记为在MirrorsUsed的镜像中使用,并且它不会过多地膨胀代码。但缩小也可能是一个问题。