我正在尝试将通知模块集成到我的应用程序中作为参考 - https://github.com/bonnici/light-bootstrap-dashboard-angularcli
构建:属性'通知'在类型' JQueryStatic'。
上不存在这是我的notification.service.ts文件,似乎是
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'
}));
}
但是,在编译期间我在$ .notify函数中收到错误,如下面的VS2015
当我用户($ as any).notify异常从VS编译中消失。但是,页面抛出一个错误$ .notify不是一个函数。
这里有任何帮助吗?
答案 0 :(得分:0)
但是,页面抛出错误$ .notify不是函数。
确保在jquery javascript之后加载了bootstrap javascript。
Bootstrap docs:http://getbootstrap.com/javascript/