我有一个父控制器和一个子控制器,两者都有publishAs: ctrl
(同名)。如果我尝试使用parent-ctrl中的参数为child-ctrl属性赋值,该属性将使用child-ctrl中的值。
以下是示例,其中my-ctrl1和my-ctrl2按预期工作,但my-ctrl3没有。
my-ctrl3的输出应为:“Child3属性消息:parent”,但现在是:“Child3属性消息:child3”
我认为这个问题也与这个问题有关:Can I put ng-if directive on an element which also binds to a controller
ang.dart:
import 'package:angular/angular.dart';
@NgController(selector: '[my-ctrl1]', publishAs: 'ctrl')
class MyCtrlController {
String m1="child1";
}
@NgController(selector: '[my-ctrl2]', publishAs: 'ctrl2')
class MyCtrl2Controller {
@NgOneWay('message')
String message;
String m1="child2";
}
@NgController(selector: '[my-ctrl3]', publishAs: 'ctrl')
class MyCtrl3Controller {
@NgOneWay('message')
String message;
String m1="child3";
}
@NgController(selector: '[parent-ctrl]', publishAs: 'ctrl')
class ParentCtrlController {
String m1="parent";
}
class MyAppModule extends Module {
MyAppModule() {
type(MyCtrlController);
type(MyCtrl2Controller);
type(MyCtrl3Controller);
type(ParentCtrlController);
}
}
void main() {
ngBootstrap(module: new MyAppModule());
}
ang.html:
<!DOCTYPE html>
<html ng-app>
<head>
<meta charset="utf-8">
<title>ng-model test</title>
<link rel="stylesheet" href="ang.css">
</head>
<body>
<div parent-ctrl>
<p>Parent m1: {{ctrl.m1}}</p><br>
<div my-ctrl1>
<p>Child1 m1: {{ctrl.m1}}</p><br>
</div>
<div my-ctrl2 message="ctrl.m1">
<p>Child2 attribute message: {{ctrl2.message}}</p>
<p>Child2 m1: {{ctrl2.m1}}</p><br>
</div>
<div my-ctrl3 message="ctrl.m1">
<p>Child3 attribute message: {{ctrl.message}}</p>
<p>Child3 m1: {{ctrl.m1}}</p>
</div>
</div>
<script src="packages/shadow_dom/shadow_dom.min.js"></script>
<script type="application/dart" src="ang.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>