问题描述
限时送ChatGPT账号..我怀疑这是一个错误,甚至可能是 https://github 的表现/angular/angular.dart/issues/396.
我想注册多个控制器,并想使用 ctrl
作为 @NgDirective
中 publishAt
字段的值.这导致第二个 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:关键词]
发布评论