Javascript $.notify不是使用typescript的函数
我正在尝试将通知模块集成到我的应用程序中,作为此处发布的参考- 生成:类型“JQueryStatic”上不存在属性“notify” 这是我的notification.service.ts文件Javascript $.notify不是使用typescript的函数,javascript,jquery,angular,typescript,notifications,Javascript,Jquery,Angular,Typescript,Notifications,我正在尝试将通知模块集成到我的应用程序中,作为此处发布的参考- 生成:类型“JQueryStatic”上不存在属性“notify” 这是我的notification.service.ts文件 import { Injectable } from '@angular/core'; export enum NotificationType { Info = 1, Success, Warning, Danger } export class NotificationOptions {
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
}
});
}
}
在我的.component.ts文件中,我像下面那样调用
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'
}));
}
但是,在编译过程中,我在VS2015中的$.notify函数处遇到错误,如下所示
- 类型“JqueryStatic”上不存在属性“notify”
- 无法正确解析符号通知,它可能位于不可访问的模块中
引导文档:您是否试图使用
deferred.progress()
和deferred.notify()
?不,我不是。我问题中的示例在VisualStudio代码中运行良好。然而,当我插入特定于it的通知组件并在visual Studio 2015中集成到我的应用程序时,它不起作用。我注意到的另一个区别是,我使用的是jQuery2+版本。而示例使用的是1.x版本。我不熟悉angular2和使用jquery。不确定为什么这不起作用。我改为使用$.deferred.notify(),UX和VS2015编译问题都消失了。但是,通知未显示在页面中,并且没有控制台错误。您是否尝试使用延迟.progress()
和延迟.notify()
?不,我没有。我问题中的示例在VisualStudio代码中运行良好。然而,当我插入特定于it的通知组件并在visual Studio 2015中集成到我的应用程序时,它不起作用。我注意到的另一个区别是,我使用的是jQuery2+版本。而示例使用的是1.x版本。我不熟悉angular2和使用jquery。不确定为什么这不起作用。我改为使用$.deferred.notify(),UX和VS2015编译问题都消失了。但是,通知没有显示在页面中,也没有控制台错误。只有在使用($as any).notify之后,我才能解决构建编译问题。在那之后,我看到了if As notify不是函数中的错误。我不理解你关于在jquery js之后加载引导js的说法。我只能在使用($As any)之后才能解决构建编译问题。notify。在那之后,我看到了if As notify不是一个函数中的错误。我不理解你关于在jquery js之后加载引导js的说法。