NotificationsBellComponent
でサービスの配列の変更を受信したいのですが。 _LocalStorageService
がデータを正しく返信しているとします。角2:コンポーネントが観測するサービスに配列を変更する方法は?
Q)コンポーネントがサービスコレクションに変更を受け取るようにするにはどうすればよいですか?
これまで成分:
@Component({
selector: 'notifications-bell',
directives: [],
templateUrl: 'build/components/notificationsBell/notificationsBell.html',
styles: [`
button{
background: none !important;
background-color: none !important;
box-shadow: none !important;
}
`]
})
export class NotificationsBellComponent {
private notifications: string[];
constructor(
private _platform: Platform,
private _nav: NavController,
private _events: Events,
private _ConfigService: ConfigurationService,
private _NotificationService: NotificationService
) {
this.notifications = this._NotificationService.notifications;
}
}
これまでサービス:
@Injectable()
export class NotificationService {
public notifications: string[];
constructor(
private _ConfigService: ConfigurationService,
private _LocalStorageService: LocalStorageService,
private _I8nService: I8nService,
private _events: Events
) {
this.getData();
}
getData() {
this._LocalStorageService.getNotifications().then((data) => {
var list: string[] = [];
if (data.res.rows.length > 0) {
for (var i = 0; i < data.res.rows.length; i++) {
list.push(data.res.rows.item(i).notification);
}
}
this.notifications = list;
});
}
addItem(description: string) {
this._LocalStorageService.addNotification(description).then(() => {
this.getData();
});
}
}
このような簡単な解決策です。そのようなルーキーエラーは私のところでは、デュは...ありがとう。 – Dave