angular.dart icon indicating copy to clipboard operation
angular.dart copied to clipboard

@NgAttr and @Ng*Way* sometimes cause errors after compilation

Open sjoqvist opened this issue 12 years ago • 5 comments

The following code generates the error No getter for 'myvalue'. and a stacktrace in the compiled Dart and JS code (tried in Dartium and Firefox) but not in the development version. I'm using Dart 1.3.6 and AngularDart 0.11.0, but the issue doesn't seem to be specific to these versions.

<!DOCTYPE html>

<html ng-app>
  <body>
    <p myctrl>Hello World!</p>

    <script type="application/dart" src="main.dart"></script>
    <script src="packages/browser/dart.js"></script>
  </body>
</html>
import 'package:angular/angular.dart';
import 'package:angular/application_factory.dart';

class AppModule extends Module {
  AppModule() { type(MyController); }
}

void main() {
  applicationFactory().addModule(new AppModule()).run();
}

@Controller(selector: '[myctrl]', publishAs: 'ctrl')
class MyController {
  MyController();
  @NgAttr('myattr') // or @NgTwoWay, @NgOneWay, @NgOneWayOneTime
  int myvalue;
}

The issue disappears when removing either the myctrl attribute from <p> or the @NgAttr annotation. Also, {{ctrl.myvalue}} can be added in the HTML, and for some reason renaming myvalue to value seems to work.

More information can be found in my Google Groups discussion with @vicb.

Here's the full stacktrace:

No getter for 'myvalue'.

STACKTRACE:
#0      StaticClosureMap.lookupGetter (package:angular/core/parser/parser_static.dart:15:25)
#1      DynamicParserBackend.newAccessScope (package:angular/core/parser/dynamic_parser.dart:108:38)
#2      DynamicParserImpl.parseAccessOrCallScope (package:angular/core/parser/dynamic_parser_impl.dart:257:67)
#3      DynamicParserImpl.parsePrimary (package:angular/core/parser/dynamic_parser_impl.dart:239:36)
#4      DynamicParserImpl.parseAccessOrCallMember (package:angular/core/parser/dynamic_parser_impl.dart:193:30)
#5      DynamicParserImpl.parsePrefix (package:angular/core/parser/dynamic_parser_impl.dart:188:37)
#6      DynamicParserImpl.parseMultiplicative (package:angular/core/parser/dynamic_parser_impl.dart:163:29)
#7      DynamicParserImpl.parseAdditive (package:angular/core/parser/dynamic_parser_impl.dart:149:37)
#8      DynamicParserImpl.parseRelational (package:angular/core/parser/dynamic_parser_impl.dart:131:31)
#9      DynamicParserImpl.parseEquality (package:angular/core/parser/dynamic_parser_impl.dart:117:33)
#10     DynamicParserImpl.parseLogicalAnd (package:angular/core/parser/dynamic_parser_impl.dart:108:31)
#11     DynamicParserImpl.parseLogicalOr (package:angular/core/parser/dynamic_parser_impl.dart:99:33)
#12     DynamicParserImpl.parseConditional (package:angular/core/parser/dynamic_parser_impl.dart:83:32)
#13     DynamicParserImpl.parseExpression (package:angular/core/parser/dynamic_parser_impl.dart:68:34)
#14     DynamicParserImpl.parseFormatter (package:angular/core/parser/dynamic_parser_impl.dart:53:33)
#15     DynamicParserImpl.parseChain (package:angular/core/parser/dynamic_parser_impl.dart:35:32)
#16     DynamicParser._parse (package:angular/core/parser/dynamic_parser.dart:36:46)
#17     DynamicParser.call.<anonymous closure> (package:angular/core/parser/dynamic_parser.dart:31:50)
#18     _HashMap.putIfAbsent (dart:collection-patch/collection_patch.dart:124)
#19     DynamicParser.call (package:angular/core/parser/dynamic_parser.dart:31:30)
#20     ElementBinder._createAttrMappings.<anonymous closure> (package:angular/core_dom/element_binder.dart:132:37)
#21     List.forEach (dart:core-patch/growable_array.dart:240)
#22     ElementBinder._createAttrMappings (package:angular/core_dom/element_binder.dart:128:21)
#23     ElementBinder._link.<anonymous closure> (package:angular/core_dom/element_binder.dart:213:30)
#24     ElementBinder._link.<anonymous closure> (package:angular/core_dom/element_binder.dart:233:9)
#25     ElementBinder._link.<anonymous closure> (package:angular/core_dom/element_binder.dart:233:9)
#26     List.forEach (dart:core-patch/growable_array.dart:240)
#27     ElementBinder._link (package:angular/core_dom/element_binder.dart:194:33)
#28     ElementBinder.bind (package:angular/core_dom/element_binder.dart:327:10)
#29     TaggingViewFactory._bindTagged (package:angular/core_dom/tagging_view_factory.dart:33:51)
#30     TaggingViewFactory._link (package:angular/core_dom/tagging_view_factory.dart:67:22)
#31     TaggingViewFactory.call (package:angular/core_dom/tagging_view_factory.dart:21:12)
#32     TaggingViewFactory.call (package:angular/core_dom/tagging_view_factory.dart:23:7)
#33     TaggingViewFactory.call (package:angular/core_dom/tagging_view_factory.dart:23:7)
#34     Application.run.<anonymous closure>.<anonymous closure> (package:angular/application.dart:174:22)
#35     _rootRunUnary (dart:async/zone.dart:730)
#36     _ZoneDelegate.runUnary (dart:async/zone.dart:462)
#37     _onRunUnary.<anonymous closure> (package:angular/core/zone.dart:114:63)
#38     VmTurnZone._onRunBase (package:angular/core/zone.dart:98:16)
#39     _onRunUnary (package:angular/core/zone.dart:114:17)
#40     _ZoneDelegate.runUnary (dart:async/zone.dart:462)
#41     _CustomizedZone.runUnary (dart:async/zone.dart:667)
#42     _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:488)
#43     _Future._propagateToListeners (dart:async/future_impl.dart:571)
#44     _Future._completeWithValue (dart:async/future_impl.dart:331)
#45     _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:393)
#46     _rootRun (dart:async/zone.dart:719)
#47     _ZoneDelegate.run (dart:async/zone.dart:453)
#48     _onScheduleMicrotask.<anonymous closure> (package:angular/core/zone.dart:122:39)
#49     _rootRun (dart:async/zone.dart:723)
#50     _ZoneDelegate.run (dart:async/zone.dart:453)
#51     VmTurnZone._finishTurn (package:angular/core/zone.dart:148:23)
#52     VmTurnZone._onRunBase (package:angular/core/zone.dart:105:43)
#53     _onRun (package:angular/core/zone.dart:110:17)
#54     _ZoneDelegate.run (dart:async/zone.dart:453)
#55     _CustomizedZone.run (dart:async/zone.dart:663)
#56     VmTurnZone.run (package:angular/core/zone.dart:219:40)
#57     Application.run (package:angular/application.dart:166:20)
#58     main (http://127.0.0.1:3030/crashapp/build/web/main.dart:12:252)

sjoqvist avatar May 15 '14 11:05 sjoqvist

This is happening to us too. Is there any workaround different that this?:

<any-component attribList="comp.theService.theList"> </any-component>

<div class="ng-hide">
  {{comp.theService.theList}}
</div>

vmendi avatar Jul 17 '14 06:07 vmendi

@aliquis @vmendi what you see are two different issues.

@aliquis the transformer do not generate getters for @NgAttr (=@) mapping. This could be solved by explicitly requiring the generation of the getter/setter with exportExpressionAttrs:

@Controller(selector: '[myctrl]', publishAs: 'ctrl', exportExpressionAttrs: const ['myattr])

However this should work for @NgTwoWay, @NgOneWay, @NgOneWayOneTime without exportExpressionAttrs` - please test with angular 0.13 and report if you still have issues.

@vmendi your issue is a bug in Angular, similar to this one from the ML. The issue here is that the current implementation of the transformer does not work well with attribute containing upper case characters (attribList). I'll submit a fix for that.

vicb avatar Aug 02 '14 11:08 vicb

@vicb I don't understand. The attribute was never used. Why would the framework complain that no getter exists for an attribute that's not used anywhere?

Anyway, I changed to @NgTwoWay and tested on both 0.13.0 and 0.14.0 and still have the same problem. Here's a minimalistic project. Am I doing anything wrong?

pubspec.yaml:
name: nogetter
version: 0.0.1
dependencies:
  angular: 0.14.0
transformers:
- angular
web/index.html:
<!DOCTYPE html>

<html ng-app>
  <body>
    <p myctrl>Hello World!</p>

    <script type="application/dart" src="main.dart"></script>
    <script src="packages/browser/dart.js"></script>
  </body>
</html>
web/main.dart:
import 'package:angular/angular.dart';
import 'package:angular/application_factory.dart';

class AppModule extends Module {
  AppModule() { bind(MyController); }
}

void main() {
  applicationFactory().addModule(new AppModule()).run();
}

@Controller(selector: '[myctrl]', publishAs: 'ctrl')
class MyController {
  MyController();
  @NgTwoWay('mystring') // or @NgAttr, @NgOneWay, @NgOneWayOneTime
  String myvalue = 'Foo';
}

Just run

pub install
pub serve

and open http://localhost:8080/ in any browser. It generates errors for me in both Dartium and Firefox.

sjoqvist avatar Aug 26 '14 09:08 sjoqvist

I don't understand. The attribute was never used. Why would the framework complain that no getter exists for an attribute that's not used anywhere?

They are not used by you but the framework use them when doing the view setup.

I can reproduce the issue, will take a look.

vicb avatar Aug 26 '14 12:08 vicb

@aliquis the issue you observe has already been fixed and merged to master on 08.25, see https://github.com/angular/angular.dart/commit/a981feb2df849fbe5aa30c4d1a60ca329287571b

vicb avatar Aug 26 '14 12:08 vicb