试图让一个简单的点击处理程序工作,这被证明非常令人沮丧。该应用程序只是一个测试应用程序来尝试不同的Angular.Dart功能。 - 使用Dart 1.6和Angular 1.0并在Dartium中运行 -
单击该按钮会抛出错误。 Ng-单击“getMe”的“无getter”。但输入和标签上的数据绑定完全正常。
示例代码
import 'package:angular/angular.dart';
import 'package:angular/application_factory.dart';
class TestMod extends Module {
TestMod() {
bind(ToggleComponent);
}
}
@Component(selector: 'toggle-comp', templateUrl: "test.html", publishAs: 'toggle')
class ToggleComponent {
String name = "";
@NgTwoWay('rating')
int rating;
ToggleComponent() {
}
void clickMe() {
print("Click");
}
}
void main() {
applicationFactory()
..addModule(new TestMod())
..run();
}
test.html文件 - 绑定适用于ng-model但不适用于ng-click
<div>
<h3>Hellos {{name}} {{rating}}!</h3>
Name: <input type="text" ng-model="name">
<button ng-click="clickMe()">Click me</button>
</div>
最后这里是index.html文件
<!DOCTYPE html>
<html ng-app >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AngularDartTest</title>
<script async type="application/dart" src="main.dart"></script>
<script async src="packages/browser/dart.js"></script>
<link rel="stylesheet" href="assets/main.css">
</head>
<body>
<toggle-comp rating="5"></toggle-comp>
</body>
</html>
按下按钮时的Stacktrace
No getter for 'clickMe'.
STACKTRACE:
#0 StaticClosureMap.lookupGetter (package:angular/core/parser/static_closure_map.dart:14:25)
#1 StaticClosureMap.lookupFunction (package:angular/core/parser/static_closure_map.dart:25:26)
#2 ClosureMapLocalsAware.lookupFunction.<anonymous closure> (package:angular/core/parser/parser.dart:253:44)
#3 CallScope.eval (package:angular/core/parser/eval_calls.dart:27:25)
#4 _UnwrapExceptionDecorator.eval (package:angular/core/parser/parser.dart:117:30)
#5 BoundExpression.call (package:angular/core/parser/syntax.dart:59:36)
#6 NgEvent._initListener.<anonymous closure> (package:angular/directive/ng_events.dart:142:39)
#7 _rootRunUnary (dart:async/zone.dart:840)
#8 _ZoneDelegate.runUnary (dart:async/zone.dart:466)
#9 _onRunUnary.<anonymous closure> (package:angular/core/zone.dart:122:63)
#10 VmTurnZone._onRunBase (package:angular/core/zone.dart:104:16)
#11 _onRunUnary (package:angular/core/zone.dart:122:17)
#12 _CustomZone.runUnary (dart:async/zone.dart:748)
#13 _CustomZone.runUnaryGuarded (dart:async/zone.dart:656)
#14 _CustomZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:682)
答案 0 :(得分:7)
问题是角度变换器无法找到test.html,因此无法解压缩clickMe getter。仅当我们在模板中的表达式中看到符号时才会生成getter。
通过getter我的意思是映射"clickMe": (o) => o.clickme
。您始终可以检查我们在main_static_expressions.dart
生成的所有getter / setter。
变压器应该是固定的(PR非常受欢迎),但同时有很多方法可以强制产生吸气剂:
答案 1 :(得分:0)
我不知道为什么name
有效,但我认为"toggle.clickMe()"
会起作用或删除publishAs
参数。