Ich versuche Benachrichtigungsmodul in meiner Anwendung zu integrieren als Referenz hier geschrieben - https://github.com/bonnici/light-bootstrap-dashboard-angularcli
Körperbau: Property ‚mitteilen‘ existiert nicht auf Typen ‚JQueryStatic‘.
Hier ist meine notification.service.ts Datei
import { Injectable } from '@angular/core';
export enum NotificationType {
Info = 1,
Success,
Warning,
Danger
}
export class NotificationOptions {
public message: string;
public icon: string = null;
public timer = 4000;
public type: NotificationType = NotificationType.Info;
public from = 'top';
public align = 'right';
public constructor(
fields: {
message: string,
icon?: string,
timer?: number,
type?: NotificationType,
from?: string,
align?: string
}) {
this.message = fields.message;
this.icon = fields.icon || this.icon;
this.timer = fields.timer || this.timer;
this.type = fields.type || this.type;
this.from = fields.from || this.from;
this.align = fields.align || this.align;
}
}
@Injectable()
export class NotificationService {
constructor() { }
public notify(options: NotificationOptions): void {
let typeString;
switch (options.type) {
case NotificationType.Success:
typeString = 'success';
break;
case NotificationType.Warning:
typeString = 'warning';
break;
case NotificationType.Danger:
typeString = 'danger';
break;
default:
typeString = 'info';
break;
}
$.notify(
{
icon: options.icon,
message: options.message
},
{
type: typeString,
timer: options.timer,
placement: {
from: options.from,
align: options.align
}
});
}
}
In meiner .component.ts Datei, wie ich rufe unter
import { NotificationService, NotificationOptions } from '../../shared/services/notification.service';
constructor(private notificationService: NotificationService) { }
ngOnInit(): void {
this.notificationService.notify(new NotificationOptions({
message: 'Welcome!',
icon: 'pe-7s-gift'
}));
}
Aber wie sieht während der Kompilierung Ich bekomme Fehler bei $ .notify Funktion wie unten in meinem VS2015
- Property ‚mitteilen‘ existiert nicht auf Typ ‚JqueryStatic‘
- Symbol benachrichtigen nicht richtig aufgelöst werden können, wahrscheinlich ist es in unzugängliche Modul befindet
wenn i Benutzer (wie jede $) .notify die Ausnahme war von VS-Compilation gegangen. Aber, Seite wirft einen Fehler $ .notify ist keine Funktion.
Irgendwelche Hilfe hier?
Versuchst du 'deferred.progress()' und 'deferred.notify()' zu benutzen? – guest271314
Nein, bin ich nicht. Das Beispiel in meiner Frage funktioniert in Visual Studio-Code. Wohingegen es nicht funktioniert, wenn ich es spezifische Benachrichtigung Komponente einstecke und zu meiner Anwendung in Visual Studio2015 integriere. Ein weiterer Unterschied, den ich bemerkte, war, ich benutze jquery 2+ Version. Während Probe die Version 1.x verwendet hat. Ich bin neu bei angular2 und benutze jquery. Nicht sicher, warum das nicht funktioniert. – Born2Code
Ich habe geändert, um $ .deferred.notify() zu verwenden, und beide UX- und VS2015-Kompilierungsprobleme sind weg. Aber die Benachrichtigung wird nicht auf der Seite angezeigt und es gibt auch keine Konsolenfehler. – Born2Code