Looking to organize my classes by creating a module where I can easily import them like a separate package. Take a look at this example:
human.ts (my class file)
export class Human {
private numOfLegs: Number;
constructor() {
this.numOfLegs = 2;
}
}
test.module.ts (my module file)
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Human } from './human';
@NgModule({
imports: [CommonModule],
declarations: [
Human
],
providers: [],
exports: [Human]
})
export class TestModule {}
Now, how do I create an instance of the Human class in a component? I've attempted importing it with both methods:
import { TestModule } from './test.module';
and
import { Human } from './test.module';
However, when trying new Human()
, I encounter the error message "cannot find name Human". Any guidance on this issue would be greatly appreciated.