I am just a new learner and following a video tutorial, my code looks like this:
import { Injectable } from '@angular/core';
import { Dish } from '../shared/dish';
import { DishService } from '../services/dish.service';
import { Observable } from 'rxjs';
import {map} from 'rxjs/operators';
import { CouchbaseService } from '../services/couchbase.service';
import * as LocalNotifications from 'nativescript-local-notifications';
@Injectable()
export class FavoriteService {
favorites: Array<number>;
docId: string = "favorites";
constructor(private dishservice: DishService,
private couchbaseService: CouchbaseService) {
this.favorites = [];
let doc = this.couchbaseService.getDocument(this.docId);
if( doc == null) {
this.couchbaseService.createDocument({"favorites": []}, this.docId);
}
else {
this.favorites = doc.favorites;
}
}
isFavorite(id: number): boolean {
return this.favorites.some(el => el === id);
}
addFavorite(id: number): boolean {
if (!this.isFavorite(id)) {
this.favorites.push(id);
this.couchbaseService.updateDocument(this.docId, {"favorites": this.favorites});
// Schedule a single notification
LocalNotifications.schedule([{
id: id,
title: "ConFusion Favorites",
body: 'Dish ' + id + ' added successfully'
}])
.then(() => console.log('Notification scheduled'),
(error) => console.log('Error showing nofication ' + error));
}
return true;
}
getFavorites(): Observable<Dish[]> {
return this.dishservice.getDishes()
.pipe(map(dishes => dishes.filter(dish => this.favorites.some(el => el === dish.id))));
}
deleteFavorite(id: number): Observable<Dish[]> {
let index = this.favorites.indexOf(id);
if (index >= 0) {
this.favorites.splice(index,1);
this.couchbaseService.updateDocument(this.docId, {"favorites": this.favorites});
return this.getFavorites();
}
else {
console.log('Deleting non-existant favorite', id);
return Observable.throw('Deleting non-existant favorite');
}
}
}
And the error I got is:
Property 'schedule' does not exist on type 'typeof import("c:/Users/m/Desktop/JS/conFusion/node_modules/nativescript-local-notifications/index")'.ts(2339)
I don't know what is the problem and how can I fix it?
As described in the plugin's read me file, use named import
import { LocalNotifications } from 'nativescript-local-notifications';