问题描述
限时送ChatGPT账号..我正在尝试将自定义事件从组件传递到其父组件/控制器
确认.html
<内容></内容><a href="#" ng-click="ctrl.yes()">是</a><a href="#" ng-click="ctrl.no()">否</a>
确认.dart
@Component(选择器:确认组件",templateUrl: 'confirm.html',使用ShadowDom:假,发布为:ctrl")类确认组件{无效是(){打印('是');//触发确认是事件}无效没有(){打印('否');//触发确认无事件}}
有这样的吗?:
你要删除吗</confirm-component>
我可以使用普通的 StreamController,但后来我不得不用代码连接我的组件.
confirmComponent.onConfirmYes.listen()ConfirmComponent.onConfirmNo.listen()
我也发现了这个:如何在 Angular DART 控制器之间进行通信
还有这个:angulardart 组件 - 调度自定义事件
在两个步骤中都提到了 scope.emit.但是我没有找到将它与组件而不是控制器一起使用的方法.是否有完整的示例 vor angular.dart v0.14.0?
scope.emit 是我正在寻找的东西吗?
解决方案这应该是一样的,只需在构造函数中添加一个范围参数,以便组件获得范围注入.
Angular 0.14.0 有一个相关的变化 https://github/angular/angular.dart/commit/181f01448555c475869505491159045904e5dc89
我还没试过这个.从描述中你需要实现 ScopeAware
@Component(...)类 MyComponent 实现了 ScopeAware {手表手表;我的组件(依赖 myDep){//向构造函数添加 Scope/RootScope 参数是错误的,将导致 DI//循环依赖错误 - 在类构造函数中永远无法访问范围}无效设置范围(范围范围){//有了这个范围,你应该能够使用emit//调用这个 setter 来初始化作用域watch = scope.rootScope.watch("表达式", (v, p) => ...);}}
I am trying to pass custom events from a component to its parent component/controller
confirm.html
<div class="comfirm-component">
<content></content>
<a href="#" ng-click="ctrl.yes()">Yes</a>
<a href="#" ng-click="ctrl.no()">No</a>
</div>
confirm.dart
@Component(
selector: "confirm-component",
templateUrl: 'confirm.html',
useShadowDom: false,
publishAs: "ctrl"
)
class ConfirmComponent {
void yes(){
print('yes');
// Fire confirm-yes event
}
void no(){
print('no');
// Fire confirm-no event
}
}
is there something like this?:
<confirm-component on-confirm-yes="doSomething()" on-confirm-no="doSomethingElse()">
Do you want to delete
</confirm-component>
I could use a normal StreamController but then i'd had to connect my components with code.
confirmComponent.onConfirmYes.listen()
confirmComponent.onConfirmNo.listen()
I also found this: How to communicate between Angular DART controllers
And this: angulardart components - dispatch custom event
In both treads scope.emit is mentioned. But i didn't find a way to use it with a component instead of a controller. Is there a full example vor angular.dart v0.14.0?
Is scope.emit the thing i'm searching for?
解决方案This should be the same, just add a scope argument to the constructor so the component gets the scope injected.
There was a related change in Angular 0.14.0 https://github/angular/angular.dart/commit/181f01448555c475869505491159045904e5dc89
I haven't yet tried this.
From the description you need to implement ScopeAware
@Component(...)
class MyComponent implements ScopeAware {
Watch watch;
MyComponent(Dependency myDep) {
// It is an error to add a Scope / RootScope argument to the ctor and will result in a DI
// circular dependency error - the scope is never accessible in the class constructor
}
void set scope(Scope scope) {
// with this scope you should be able to use emit
// This setter gets called to initialize the scope
watch = scope.rootScope.watch("expression", (v, p) => ...);
}
}
这篇关于Angular Dart 组件事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论