There are two modules in my project, a root module and a shared module. Below is the code for the shared module:
import { NgModule } from '@angular/core';
import { SomeComponent } from "./somecomponent";
@NgModule({
declarations: [SomeComponent],
exports: [SomeComponent]
})
export class SomeModule {}
In my Root module, I import the SomeModule
like this:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { SomeModule } from somemodule/somemodule';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, SomeModule],
bootstrap: [AppComponent],
})
export class AppModule {}
Everything works perfectly until now. Now, I want to access a method that belongs to SomeComponent
inside my app.component
. However, the issue is that the shared module does not directly expose SomeComponent
.
How can I call methods from SomeComponent
in the AppComponent
class? What if the method is static
?
EDIT : To clarify further, SomeComponent
is a directive that I am able to use in the template of
AppComponent</code without any problems. However, it also contains a static method that I need to call within the <code>AppComponent
class. Since I have imported it in the Root module, it should be available inside the AppComponent. I would like something similar to this in the AppComponent:
import {Component} from '@angular/core';
@Component({
selector: 'my-app',
template: `<some-component (someEvent)="handle($event)"></some-component>`
})
export class AppComponent {
_constructor(){}
handle(event){
SomeComponent.someStaticMethod();
}
}