我只是一个新手,在学习了视频教程之后,我的代码如下:
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');
}
}
}
我得到的错误是:
类型“ typeof”上不存在属性“计划” import(“ c:/ Users / m / Desktop / JS / conFusion / node_modules / nativescript-local-notifications / index”)'。ts(2339)
我不知道问题出在哪里,如何解决?
答案 0 :(得分:0)
如插件的自述文件中所述,请使用名为import
import { LocalNotifications } from 'nativescript-local-notifications';