Do publishAs values have to be unique in Angular Dart?

血红的双手。 提交于 2019-12-11 13:02:01

问题


I suspect this is a bug, possibly even a manifestation of https://github.com/angular/angular.dart/issues/396.

I want to register multiple controllers and want to use ctrl as the value of the publishAt field within @NgDirective. This leads to the second ctrl clobbering the value of the first one, even though they exist in different scopes.

Here is the view:

<!DOCTYPE html>
<html>
  <body>    
    <div>
      <div foo-controller>

        <!-- PRINTS 'bar'. -->
        <p>{{ctrl.item}}</p>
      </div>

      <div bar-controller>
        <!-- PRINTS 'bar'. -->           
        <p>{{ctrl.item}}</p>
      </div>
    </div>

    <script type="application/dart" src="main.dart"></script>
    <script type="text/javascript" src="packages/browser/dart.js"></script>
  </body>
</html>

And here is the Dart code:

import 'package:angular/angular.dart';

@NgDirective(
  selector: '[foo-controller]',
  publishAs: 'ctrl'
)
class FooController {
  String item = 'foo';
}

@NgDirective(
  selector: '[bar-controller]',
  publishAs: 'ctrl'
)
class BarController {
  String item = 'bar';
}

main() {
  ngBootstrap(module: new Module()
      ..type(FooController)
      ..type(BarController));
}

The output is 'bar' both times. If I make the publishAs values unique, the output is 'foo' followed by 'bar'.

Is this a bug or am I misunderstanding how scopes work?


回答1:


Duplicate of: https://github.com/angular/angular.dart/issues/396 Puzzled by CSS selector to trigger controller




回答2:


You should use @NgController rather than @NgDirective



来源:https://stackoverflow.com/questions/21009394/do-publishas-values-have-to-be-unique-in-angular-dart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!