使用 bootstrap-通知 Angular 7
Using bootstrap-notify with Angular 7
我想在我的 Angular 7 应用程序中使用 bootstrap-notify
。
为此,我安装了 bootstrap-notify
软件包(以及 @types/bootstrap-notify
)。
在我想要使用通知的组件中,我导入了 jQuery 服务,如下所示:
import * as $ from 'jquery';
现在称为 notify
,如文档中 here 所述:
$.notify({
// options
message: 'Hello World'
},{
// settings
type: 'danger'
});
问题是我得到这个错误:
ERROR in src/app/home/home.component.ts(28,7): error TS2339: Property 'notify' does not exist on type 'JQueryStatic'.
知道如何让它发挥作用吗?我找不到任何使用此包的 Angular (5/6/7) 示例!
您可以尝试以下方法。
1) jquery 的第一个安装类型定义:
npm install @types/jquery
2) 然后在组件文件中导入jquery并通知使用
import * as $ from 'jquery';
import 'bootstrap-notify';
$[`notify`](....);
3) 最后,您还需要添加 css file/link 以查看其实际样式。
演示https://stackblitz.com/edit/angular-custom-alert-message-hqrysq?file=app%2Fapp.component.ts
有时它会抛出错误,但如果您在代码中添加一些空格并保存它,它就会正常运行。
我想在我的 Angular 7 应用程序中使用 bootstrap-notify
。
为此,我安装了 bootstrap-notify
软件包(以及 @types/bootstrap-notify
)。
在我想要使用通知的组件中,我导入了 jQuery 服务,如下所示:
import * as $ from 'jquery';
现在称为 notify
,如文档中 here 所述:
$.notify({
// options
message: 'Hello World'
},{
// settings
type: 'danger'
});
问题是我得到这个错误:
ERROR in src/app/home/home.component.ts(28,7): error TS2339: Property 'notify' does not exist on type 'JQueryStatic'.
知道如何让它发挥作用吗?我找不到任何使用此包的 Angular (5/6/7) 示例!
您可以尝试以下方法。
1) jquery 的第一个安装类型定义:
npm install @types/jquery
2) 然后在组件文件中导入jquery并通知使用
import * as $ from 'jquery';
import 'bootstrap-notify';
$[`notify`](....);
3) 最后,您还需要添加 css file/link 以查看其实际样式。
演示https://stackblitz.com/edit/angular-custom-alert-message-hqrysq?file=app%2Fapp.component.ts
有时它会抛出错误,但如果您在代码中添加一些空格并保存它,它就会正常运行。