在 Angular Dart 中,publishAs 值必须是唯一的吗? [英] Do publishAs values have to be unique in Angular Dart?

查看:21
本文介绍了在 Angular Dart 中,publishAs 值必须是唯一的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怀疑这是一个错误,甚至可能是 https://github 的表现.com/angular/angular.dart/issues/396.

我想注册多个控制器,并想使用 ctrl 作为 @NgDirectivepublishAt 字段的值.这导致第二个 ctrl 破坏第一个的值,即使它们存在于不同的作用域中.

这是视图:

<身体><div><div foo-controller><!-- 打印条".--><p>{{ctrl.item}}</p>

<div栏控制器><!-- 打印条".--><p>{{ctrl.item}}</p>

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

这是 Dart 代码:

import 'package:angular/angular.dart';@NgDirective(选择器:'[foo-controller]',发布为:'ctrl')类 FooController {字符串项 = 'foo';}@NgDirective(选择器: '[bar-controller]',发布为:'ctrl')类 BarController {String item = 'bar';}主要的() {ngBootstrap(模块:新模块()..type(FooController)..type(BarController));}

两次输出都是 'bar'.如果我使 publishAs 值唯一,则输出为foo"后跟bar".

这是一个错误还是我误解了范围的工作原理?

解决方案

重复:https://github.com/angular/angular.dart/issues/396困惑于 CSS 选择器触发控制器

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?

解决方案

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

这篇关于在 Angular Dart 中,publishAs 值必须是唯一的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆