Property 'darkModeService' does not exist on type 'LoanComponent'

Advertisements

i am trying to make my angular app runt with dark theme, and i have set it up correctly but it doesent work

Code:

 constructor(private bookService: BookService, private categoryService: CategoryService,  private formBuilder: FormBuilder, darkModeService: DarkModeService) {}
  range = new FormGroup({
    fromDate: new FormControl('', Validators.required),
    toDate: new FormControl('', Validators.required)
  });


darkMode$: Observable<boolean> = this.darkModeService.darkMode$;// and here

  ngOnInit(): void {
    this.dateRangeForm = this.formBuilder.group({
      fromDate: new FormControl('', Validators.required),
      toDate: new FormControl('', Validators.required)
    });

  }
  onToggle(): void {
    this.darkModeService.toggle();//error happens here
  }

>Solution :

Could you please say where is you DarkModeService provided?

Beside this, please try the following in the constructor of your class (added private beside darkModeService: DarkModeService):

constructor(private bookService: BookService, 
            private categoryService: CategoryService,  
            private formBuilder: FormBuilder, 
            private darkModeService: DarkModeService) {} // add private here
  range = new FormGroup({
    fromDate: new FormControl('', Validators.required),
    toDate: new FormControl('', Validators.required)
  });


darkMode$: Observable<boolean> = this.darkModeService.darkMode$;// and here

  ngOnInit(): void {
    this.dateRangeForm = this.formBuilder.group({
      fromDate: new FormControl('', Validators.required),
      toDate: new FormControl('', Validators.required)
    });

  }
  onToggle(): void {
    this.darkModeService.toggle();//error happens here
  }

Instead of private, you can use public or readonly as well. Since im not aware of your project, im not sure which one fits you the best.

Leave a ReplyCancel reply