dart - 为什么使用 angular.dart 0.10 和 ng-view 会出现 js 执行错误?

标签 dart angular-dart

我刚刚迁移到 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/

相关文章:

angularjs - 使用为angular.js编写的第三方依赖项

firebase - Firestore如何从文档快照流中的快照访问值

dart - 在 flutter 中使用 google map 时出现错误

javascript - 在 Angular2js/Dart 中将变量传递给 html 页面

dart - 访问子组件中的父组件变量(ng-view嵌套路由)

dart - AngularDart 可以直接路由到组件吗?

dart - 在 Angular Dart 中更改 HTML 的 <head> 中的值

dictionary - 如何设置像 “Map<String, bool>”这样的 map

angular - Dart Angular 路线参数不起作用

angular - 如何删除 Dart Angular2 教程中的 "property binding not used by any directive"错误?