我刚刚迁移到 angular-0.10.0 。我的应用程序在 Dartium 中按预期工作,但在 js 中通过 dart2js 我在 Web 控制台中收到以下未缩小的错误:
No getter for 'ctrl'.
STACKTRACE:
Error
at dart.wrapException (http://localhost:8080/app/main.dart.js:2390:15)
at StaticClosureMap.lookupGetter$1 (http://localhost:8080/app/main.dart.js:8926:17)
at DynamicParserBackend.newAccessScope$1 (http://localhost:8080/app/main.dart.js:7177:21)
at DynamicParserImpl.parseAccessOrCallScope$0 (http://localhost:8080/app/main.dart.js:7531:29)
at DynamicParserImpl.parsePrimary$0 (http://localhost:8080/app/main.dart.js:7507:21)
at DynamicParserImpl.parseAccessOrCallMember$0 (http://localhost:8080/app/main.dart.js:7464:21)
at DynamicParserImpl.parsePrefix$0 (http://localhost:8080/app/main.dart.js:7460:21)
at DynamicParserImpl.parseMultiplicative$0 (http://localhost:8080/app/main.dart.js:7439:21)
at DynamicParserImpl.parseAdditive$0 (http://localhost:8080/app/main.dart.js:7428:21)
at DynamicParserImpl.parseRelational$0 (http://localhost:8080/app/main.dart.js:7413:21)
pubspec.yaml
name: app
version: 0.0.1-dev
dependencies:
angular: any
browser: any
dev_dependencies:
unittest: any
transformers:
- angular
Controller :
@Controller(selector: '[myCtrl]', publishAs: 'ctrl')
class MyController {
String search = 'test';
}
html 模板:
<div myCtrl>
<input ng-model="ctrl.search"></input>
{{ ctrl.search }}
</div>
该错误仅出现在 <ng-view>
内。如果我直接在主html中添加上面的html,则不会出现js错误。
最佳答案
Pavel Jbanov 在 this post 中指出:
I believe expression_generator transformer is unable to discover your template file, so you might need to manually include it: https://github.com/angular/angular.dart/blob/master/lib/tools/transformer/options.dart#L17
以及进一步:
The transformer will hopefully get better at identifying template files so you don't have to manually list them. Right now, afaik, it only picks up template files of components.
因此,现在您必须在 pubspec.yaml
中手动添加所有未跟踪的 html 模板,如下所示 html_files
部分:
name: app
version: 0.0.1-dev
dependencies:
angular: any
browser: any
dev_dependencies:
unittest: any
transformers:
- angular:
html_files:
- web/template1.html
- web/template2.html
- web/template3.html
关于dart - 为什么使用 angular.dart 0.10 和 ng-view 会出现 js 执行错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23263222/