我有两个组件如下所示,我想从另一个组件中调用一个函数。这两个组件都使用指令包含在第三个父组件中。 组件1:@component( selector:'com1' ) export class com1{ function1(){...} } 组件 2:@component( ...
在Angular应用程序中,我注意到@Component具有属性moduleId。这是什么意思? 当module.id在任何地方都没有被定义时,该应用程序仍然可以工作。它是如何工作的?@Component({ moduleId: module.id, selector: 'ng-ap...
我有自定义组件:@Component({ selector: 'my-custom-component', templateUrl: './my-custom-component.html', styleUrls: ['./my-custom-component.css...
我有一个实现,父组件想通过在子组件中使用的 @Input 参数向子组件传递某些数据。然而,这种数据传输是可选的,根据需求,父组件可能会或者不会传递它。组件中是否可以有可选的输入参数?我在下面描述了一个场景: <parent> <child [showName]="tr...
给定以下代码,我尝试测试Angular2的ngOnChanges生命周期钩子:import { it, inject, fdescribe, beforeEachProviders, } from '@angular/core/testing'; import...
我玩过Angular 2组件及其组合,并遇到了丑陋的行为,这是由原生事件冒泡和@Output名称冲突引起的。我有一个名为app-form的组件,其中包含模板中的表单。<form (ngSubmit)="submitButtonClicked($event)"> <inpu...
我有一个Angular 2组件,想要通过id检索元素div <div id ="myId">。在我的组件(TypeScript)中尝试使用document.getElementById("myId"),但是出现错误:“无法找到名称文档”。我看到在其他帖子中,我们可以使用@ViewC...
我有一个父组件,点击链接后会打开一个新的组件,这个新的组件应该有一个关闭按钮,关闭时会向父组件发送关闭消息并销毁自身。 我们可以使用 ngOnDestroy 方法发送关闭消息,但如何调用子组件的销毁呢?<parent> <child></child>...
我想创建一个服务,它可以与一个组件交互。 我的应用程序中的所有其他组件都应该能够调用此服务,而此服务应该与这个组件进行交互。 如何从服务中调用组件方法?@Component({ selector:'component' }) export class Component{ func...
我正在尝试找出如何访问我们传递到 @Component 装饰器中的 selector。 例如: @Component({ selector: 'my-component' }) class MyComponent { constructor() { // I was ho...