代码之家  ›  专栏  ›  技术社区  ›  rickb

*不在省道角度下工作(4)

  •  0
  • rickb  · 技术社区  · 8 年前

    pubspec如下所示:

    name: angular4_basic
    description: A web app that uses AngularDart Components
    version: 0.0.1
    #homepage: https://www.example.com
    #author: Rick Berger <email@example.com>
    
    environment:
      sdk: '>=1.24.0 <2.0.0'
    
    dependencies:
      angular: ^4.0.0
      angular_components: ^0.6.0
    
    dev_dependencies:
      browser: ^0.10.0
      dart_to_js_script_rewriter: ^1.0.1
    
    transformers:
    - angular:
        entry_points:
          - web/main.dart
    - dart_to_js_script_rewriter
    

    这是主要的。投掷:

    import 'package:angular/angular.dart';
    
    import 'package:angular4_basic/app_component.dart';
    
    void main() {
      bootstrap(AppComponent);
    }
    

    <h1>The Beatles</h1>
    
    <ul>
      <li *ngFor="let name of names">{{name}}</li>
    </ul>
    

    和app_组件。dart看起来像这样:

    import 'package:angular/angular.dart';
    import 'package:angular_components/angular_components.dart';
    
    @Component(
      selector: 'my-app',
      styleUrls: const ['app_component.css'],
      templateUrl: 'app_component.html',
      directives: const [materialDirectives],
      providers: const [materialProviders],
    )
    class AppComponent {
      List<String> names = <String>['George', 'Paul', 'Ringo', 'John'];
    }
    

    我发现以下错误:

    *ngFor="let name of names"
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
    line 4, column 3 of AppComponent: ParseErrorLevel.FATAL: Property binding ngForOf not used by any directive on an embedded template
    <li *ngFor="let name of names">
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    

    ... 然后是一个大而长的堆栈跟踪

    • 将“*ngFor”替换为“<ng模板ngFor&燃气轮机</ng模板>'语法——它创建了一个未解析的。

    • 使用dartdevc编译器

    2 回复  |  直到 8 年前
        1
  •  5
  •   Feu    8 年前

    在指令列表中MaterialDirections旁边添加NgFor或CORE_指令

        2
  •  0
  •   Lazar Ljubenović    8 年前

    你错过了 let name 是上帝给予的东西 ngFor structural指令,并使用此信息构建下面的模板”。

    ngFor公司 将为您提供来自 names

    这在结构指令的分解形式中更容易看到。

    <ng-template [ngForOf]="names" let-name>
      {{ name }}
    </ng-template>
    

    基本上,模板是 一个函数(它不是一个很好的心智模型),以及 是一个论点。根据参数编写模板的外观,然后 ngFor公司

    这个“参数”被称为 ,而您没有指定上下文的名称这一事实意味着您使用了 含蓄的 还提供了其他“参数”(上下文中的其他值),例如 index first .

    <ng-template [ngForOf]="names" let-name let-i="index">
      {{ i }}. {{ name }}
    </ng-template>
    

    指数 并将其分配给一个变量 i 一、 在模板内部。这类似于具有参数名称的函数 一、 然后用一个名为 指数

    function render(i) { return i }
    for (let index = 0; index < 3; index++) {
      render(index)
    }