0

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.

2 Answers 2

1

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) { }
Sign up to request clarification or add additional context in comments.

Comments

1

The constructor is constructor(public share: ShareModule) { }. It is expecting an argument of type ShareModule. But you are not passing any.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.