问题标签 [angular-event-emitter]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
80 浏览

angular - 在 window.close 事件上调用事件

我有一个代码可以在打开的窗口上创建一个新用户。所以我想在window.close上触发一个偶数。谁能帮我解决这个问题。

我的代码是这样的

上面的代码将在新窗口上打开一个链接。如何在关闭打开的窗口时调用函数?我想在单击关闭按钮时调用一个函数

0 投票
1 回答
2772 浏览

angular - Angular 9 - 事件发射器不发射

我正在尝试使用事件发射器将数据从表单组件传递到模态组件。以下是我如何配置它 -

表格.ts

表单-modal.html

表单 Modal.ts

下面是我得到的输出:

在此处输入图像描述 我的Form Module如下-Form(Folder) Form.html Form.ts Form-Modal(Folder) Form-Modal.html Form-Modal.ts 请帮忙。如果您需要更多信息,请告诉我。

谢谢!阿迪亚普拉卡什

0 投票
1 回答
1767 浏览

angular - Angular EventEmitter 似乎不起作用

我有一个主组件,它调用一个子组件,它是一个切换面板,当我激活切换时,它会发出切换的值(真或假)

切换面板.component.ts

当我以这种方式使用此组件时:

main.component.html

它工作得很好, isToggle 的值发生了变化。

但是当我这样使用它时:

main.component.html

在主要组件中使用此功能:

main.component.js

当我切换切换时,永远不会调用 onToggleChange 函数,我不明白为什么。

问题是当“toggleValue”的值发生变化时,我必须调用函数发出。

我还尝试使用 ngOnChanges 来检测“toggleValue”的变化,但即使在切换面板组件中调用了发出函数,ngOnChanges 也没有检测到变化。

我该如何解决这个问题?

0 投票
1 回答
350 浏览

angular - 从服务 Angular 发出事件

组件代码

服务代码

在阅读此链接时能够知道在服务中使用 eventemitter 是不好的做法。上面的代码完美运行我的问题是我有 formData 的通用函数,它获取表单的值取决于 tabclick 值。第一次事件在单击时按预期发射其他选项卡,即第二次单击其发射两次,第三次其发射 3 次 4 表示 4 次任何人都可以建议我最好的方法,我是 ne 角度

0 投票
1 回答
50 浏览

angular - Angular EventEmitter 将参数传递给父级

我正在使用 Angular 9。在登录事件中,我需要将凭据从子级(登录组件)传递给父级(安全组件)。

在登录组件中,当提交表单时,会触发一个事件:

我想在父安全组件中订阅该事件。所以我尝试以下方法:

问题是console.log('subscribed', item)永远不会被调用。

问题

我如何订阅this.changed.emit('changed!!');

更多信息

我有以下内容:

security.component.html(有一个子登录指令)

security.component.html

登录组件.ts

0 投票
1 回答
1699 浏览

angular - 未调用 Angular 单元测试中的事件发射器

鉴于此组件...

...和这个模板...

...然后此测试失败:

测试输出为:

该功能在浏览器中有效,但此测试设置中的某些内容是错误的。

0 投票
0 回答
211 浏览

angular - Emit and Subscribe within Angular 9 Service don't work together

I have service called shopping list service.

In the function addIngredientsFromRecipes() I „receive“ an Array of type Ingredient, which is different from the initial ingredients Array in the Service. The array I receive looks like this. (Running the first console.log in addIngredientsFromRecipes())

In this function I also want to add the “received“ Ingredients Array to the initial ingredients Array of the service. This works because when I console.log it (second console.log in the function), it shows the initial Array with the extra Array.

The problem starts when I want to send this new Array to the Component which displays the Array via this.ingredientEmitter.emit(this.ingredients) in the function addIngredient(ingredient:Ingredient).

The HTML Template of the displaying component look like this:

The ts of the displaying component:

It seems that the subscription dosent seem to work for some reason. Can`t figure out why. Many thanks in advance.

0 投票
1 回答
177 浏览

angular - ngOnInit 在 Angular 的组件内初始化 EventEmitter 变量是否太晚了?

我尝试使用以下子组件类

在父模板中,我将上述组件引用为

它导致了这个错误:Cannot read property 'subscribe' of undefined...页面加载。当我后来根据朋友的建议,将 EventEmitter 初始化从 ngOnInit 移到构造函数时,一切正常。

那么,在 ngOnInit 中初始化组件变量是否为时已晚?

0 投票
1 回答
208 浏览

angular - 使用事件发射器将数据从购物车传递到 Angular 的结帐页面

我目前正在处理购物车,我想将在购物车页面上输入的数量和其他数据传递到结帐页面。我尝试了不同的方法,但我无法得到它。

这是我的Cart.component.ts

和我的cart.component.html

谢谢

0 投票
3 回答
509 浏览

javascript - Angular 2阻止子组件单击时的路由器导航

我有一个模板

在我的组件中,这里是处理程序

我想在复选框单击时什么也不做,而是在 div 单击时路由。

上述解决方案不起作用。