在 Angular Dart 中,publishAs 值必须是唯一的吗?

编程入门 行业动态 更新时间:2024-10-28 02:20:49
本文介绍了在 Angular Dart 中,publishAs 值必须是唯一的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我怀疑这是一个错误,甚至可能是 https://github 的表现/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/angular/angular.dart/issues/396困惑于 CSS 选择器触发控制器

I suspect this is a bug, possibly even a manifestation of https://github/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/angular/angular.dart/issues/396 Puzzled by CSS selector to trigger controller

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

更多推荐

[db:关键词]

本文发布于:2023-04-22 12:01:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023491.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是唯一   Angular   Dart   publishAs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!