2017-05-02 96 views
0

我想作为参考贴在这里,以通知模块在我的应用程序集成功能 - 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

  • 住宅“通知”不存在于型“JqueryStatic”
  • 符号通知不能得到妥善解决,很可能它位于人迹罕至模块

当我的用户($任何).notify的例外是从VS编译。但是,页面抛出错误$ .notify不是一个函数。

这里有什么帮助吗?

+0

你是不是想用'deferred.progress()'和'deferred.notify()'? – guest271314

+0

不,我不是。我的问题中的示例在Visual Studio代码中工作正常。然而,当我在Visual Studio2015中插入特定的通知组件并将其集成到我的应用程序中时,它不起作用。我注意到的另一个区别是,我正在使用jquery 2+版本。而样本使用1.x版本。我是新来的angular2和使用jQuery。不知道为什么这不起作用。 – Born2Code

+0

我更改为使用$ .deferred.notify(),UX&VS2015编译问题都消失了。但是,通知并未显示在页面中,也没有控制台错误。 – Born2Code

回答

0

但是,页面抛出错误$ .notify不是一个函数。

请确保引导JavaScript是在jquery javascript之后加载的。

更多

引导文档:http://getbootstrap.com/javascript/

+0

我只能在使用($ as any).notify之后才能解析构建编译。之后,我看到if中的错误。通知不是函数。 – Born2Code

+0

我不明白你的jquery js加载bootstrap js的声明。 – Born2Code