0

I am new to angular, I am using the method, it's very confusing for me. I have a method and inside I have another method. but while running I got this error in the console - this.getAllJobs is not a function

my content component:

<mat-radio-group class="pl-30 pr-30 d-flex flex-column"  [(ngModel)]="visibility" (ngModelChange)="filterChange()">
      <p class="secondary-color fz-14 sf-medium"  [textContent]="'filter.visibility' | translate"></p>
      <mat-radio-button class="mb-10" [value]=null>{{'filter.all' | translate}}</mat-radio-button>
      <mat-radio-button class="mb-10" *ngFor="let visibility of jobVisibilities"
                        [value]="visibility">{{'job.visibility.'+visibility | translate}}</mat-radio-button>
</mat-radio-group>

here iam calling the method. my content component ts:

public getAllJobs: any;
filterChange(){
     this.getAllJobs({"visibility": this.visibility, "timeRequirement":this.timeRequirement,"duration":this.duration,"payment":this.payment,"experience":this.experience});}

header component.ts:

getAllJobs(filterName?:any) {
this.jobService.findAll(this.getQuery(filterName)).subscribe((res: Page<Job>) => {
  this.jobs = res;
},
error => {
  this.messages = error;
})}

here angular extent method I used. i'am passing data from the content component click event to header component. here I used (this) type only. but I am getting this error. Does anyone know how to fix this?

Sankar S
  • 207
  • 3
  • 12
  • Where is filterChange called? Probably youre missing a `.bind(this)` on the call. – mamichels Jul 01 '20 at 14:09
  • @mamichels sorry I missed HTML...i added now – Sankar S Jul 01 '20 at 14:22
  • did you ever assign a function to the `getAllJobs` property? in your example you've just declared it, never given it a value. – Andreas Turku Jul 01 '20 at 14:40
  • `getAllJobs: any;` ->This is variable of type `any` . `getAllJobs(): any { ...}` ->This is function with return type `any` – Wasim Jul 01 '20 at 14:48
  • @AndreasTurku I edited and I added. its another component. – Sankar S Jul 01 '20 at 14:51
  • if it's in another component, you can't call it this way. when you're calling `this.getAllJobs(...` it's trying to execute the method in the the same component, which you've declared as `public getAllJobs: any;` (which is the same as declaring it as `public getAllJobs = undefined`) undefined is not a function and can't be called, which would explain your error. – Andreas Turku Jul 01 '20 at 15:01
  • @AndreasTurku any other ways to use this? how to pass that data to another component? – Sankar S Jul 01 '20 at 15:03
  • This SO can help you with that question: https://stackoverflow.com/questions/31026886/how-do-i-share-data-between-components-in-angular-2 – Andreas Turku Jul 01 '20 at 15:08
  • @AndreasTurku thanks..i will check it – Sankar S Jul 01 '20 at 15:16

0 Answers0