Reputation: 2710
Im kinda new working with typescript i haven this small test file im using to practice, and still dont get what is wrong here.
app.ts
import * as $ from 'jquery';
import { ShareModule } from './modules/share.module';
export class AppModule {
constructor(public share: ShareModule) { }
public getphotos(): void {
this.share.logPhotos();
}
}
const app = new AppModule();
share.module.ts
import * as $ from 'jquery';
export class ShareModule {
public photos: any = [
{ name: 'string' },
{ name: 'string' },
{ name: 'string' },
{ name: 'string' },
{ name: 'string' },
{ name: 'string' }
];
constructor() {
}
public logPhotos(): void {
this.photos.forEach((photo) => {
console.log(photo);
});
}
}
someone to help to understand why is wrong and where is error on the code, just to make a little bit more clear i have the error the const app = new Appmodule
is expecting 1 argument and get 0.
Upvotes: 0
Views: 68
Reputation: 4553
Constructor of AppModule
requires a parameter. So a param has to be passes while using new AppModule()
. Constructor param can be made optional by
constructor(public share ?: ShareModule) { }
Upvotes: 1
Reputation: 3526
The constructor is constructor(public share: ShareModule) { }
. It is expecting an argument of type ShareModule
. But you are not passing any.
Upvotes: 1