当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

angular-web-notification

Web Notifications AngularJS Service
授权协议 Apache-2.0 License
开发语言 JavaScript
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 翟永春
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

angular-web-notification

CI

Web Notifications AngularJS Service

Overview

The angular-web-notification is an angular service wrapper for the web notifications API.

It is using the simple-web-notification library which provides a simple and easy notification API which works across browsers and provides automatic permission handling.

See W3 Specification and simple-web-notification for more information.

Angular 2 and Up

For angular 2 and above, it is recommanded to use the simple-web-notification library directly.
It provides the same API and it is not dependend on angular.

Demo

Live Demo

Usage

In order to use the angular service you first must add the relevant dependencies:

<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="simple-web-notification/web-notification.js"></script>
<script type="text/javascript" src="angular-web-notification.js"></script>

Next you must define it as a dependency in your main angular module as follows:

angular.module('exampleApp', [
    'angular-web-notification'
]);

Now you can inject and use the service into your modules (directives/services/...), for example:

angular.module('exampleApp').directive('showButton', ['webNotification', function (webNotification) {
return {
    ...
    link: function (scope, element) {
        element.on('click', function onClick() {
            webNotification.showNotification('Example Notification', {
                body: 'Notification Text...',
                icon: 'my-icon.ico',
                onClick: function onNotificationClicked() {
                    console.log('Notification clicked.');
                },
                autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
            }, function onShow(error, hide) {
                if (error) {
                    window.alert('Unable to show notification: ' + error.message);
                } else {
                    console.log('Notification Shown.');

                    setTimeout(function hideNotification() {
                        console.log('Hiding notification....');
                        hide(); //manually close the notification (you can skip this if you use the autoClose option)
                    }, 5000);
                }
            });
        });
    }
};
}]);

In case you wish to use service worker web notifications, you must provide the serviceWorkerRegistration in the options as follows:

//Get the service worker registeration object at the startup of the application.
//This is an aysnc operation so you should not try to use it before the promise is finished.
var serviceWorkerRegistration;
navigator.serviceWorker.register('service-worker.js').then(function(registration) {
    serviceWorkerRegistration = registration;
});

//when setting on even handlers in different areas of the application, use that registration object instance (must be done after the registration is available)
element.on('click', function onClick() {
    webNotification.showNotification('Example Notification', {
        serviceWorkerRegistration: serviceWorkerRegistration,
        body: 'Notification Text...',
        icon: 'my-icon.ico',
        actions: [
            {
                action: 'Start',
                title: 'Start'
            },
            {
                action: 'Stop',
                title: 'Stop'
            }
        ],
        autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
    }, function onShow(error, hide) {
        if (error) {
            window.alert('Unable to show notification: ' + error.message);
        } else {
            console.log('Notification Shown.');

            setTimeout(function hideNotification() {
                console.log('Hiding notification....');
                hide(); //manually close the notification (you can skip this if you use the autoClose option)
            }, 5000);
        }
    });
});

Installation

Run npm install in your project as follows:

npm install --save angular-web-notification

Or if you are using bower, you can install it as follows:

bower install angular-web-notification --save

Limitations

The web notifications API is not fully supported in all browsers.

Please see supported browser versions for more information on the official spec support.

API Documentation

See full docs at: API Docs

Contributing

See contributing guide

Release History

Date Version Description
2020-05-13 v2.0.1 Revert bower.json deletion but not use it in CI build
2020-05-11 v2.0.0 Migrate to github actions, upgrade minimal node version and remove bower
2019-02-08 v1.2.31 Maintenance
2017-08-25 v1.2.24 Document support of service worker web notifications
2017-01-22 v1.2.0 Split the internal web notification API into a new project: simple-web-notification
2016-11-23 v1.0.19 Use forked version of html5-desktop-notifications in order to resolve few issues
2016-11-04 v1.0.16 Upgrading to html5-desktop-notifications 3.0.0
2016-09-10 v1.0.6 Default to website favicon.ico if icon not provided in options
2016-09-07 v1.0.4 Callback is now optional
2016-06-14 v0.0.78 Published via NPM (in addition to bower)
2016-03-08 v0.0.65 Added webNotification.permissionGranted attribute
2015-09-26 v0.0.31 Update bower dependencies
2015-09-26 v0.0.30 Added 'onClick' option to enable adding onclick event handler for the notification
2015-08-16 v0.0.22 uglify fix
2015-02-16 v0.0.7 Automatic unit tests via karma
2015-02-05 v0.0.5 Doc changes
2014-12-09 v0.0.3 API now enables/disables the capability to automatically request for permissions needed to display the notification.
2014-12-08 v0.0.2 Initial release

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.

  • 第一次写博,鼓励自己一下! 首先:上bug! What went wrong: Could not resolve all files for configuration ‘:app:releaseCompileClasspath’. Could not resolve com.android.support:support-v4:26.+. Required by: project :app F

  • 更新 : 2019-06-29  自从 pwa 一推出开始玩了一把,一直到现在才真的有项目需求... 重新整理了一下.  https://angular.io/guide/service-worker-getting-started 跟着 get start 走,基本上 3 个 command 就搞定了. 真实方便呢 下面提一提需要留意的东西  Hash Mismatch 问题 如果我们用 liv

  • PWA (Progressive Web App) 1、简介 是一种理念,使用多种技术来增强web app的功能,可以让网站的体验变得更好,能够模拟一些原生的功能,比如:通知推送 Js-to-Native与以PWA为首的纯web应用,将分别从两个方向挤压Hybrid的生存空间,消化当前Hybird架构主要解决的问题 IOS目前还不支持PWA 2、下一代web应用 2.1 优点 webpack、Ro

  • rxjs angular In this tutorial, we'll learn to use the RxJS 6 library with Angular 6 or Angular 7. We'll learn about: 在本教程中,我们将学习将RxJS 6库与Angular 6或Angular 7结合使用。我们将了解: How to import the Observable cla

  • NG-ZORRO 7.0.0 发布了,NG-ZORRO 是 Ant Design 的 Angular 实现,用于开发和服务于企业级后台产品。 开发团队表示,距离上一个稳定版本的发布已经有 3 个月的时间,从 7.0 版本开始,ng-zorro-antd 将和其他 Angular 第三方库一样,保持与 Angular 的主版本号一致。按照路线图的规划,开发团队在 7.0 前三个 rc 版本的基础上增

  •   chsakell分享了一个前端使用AngularJS,后端使用ASP.NET Web API的项目。   源码: https://github.com/chsakell/spa-webapi-angularjs 文章:http://chsakell.com/2015/08/23/building-single-page-applications-using-web-api-and-angula

  • 前后端分离的项目,大多都是无状态的,我们使用JSON Web Tokens进行身份验证,但是每次请求都手动添加token这种事情是不可能做的,因为懒,这里就要用到拦截器Interceptor 创建src/app/app-auth-interceptor.module.ts实现拦截器 intercept(req: HttpRequest<any>, next: HttpHandler): Obs

  • angular ionic 免费试用IBM Cloud 使用IBM Cloud Lite快速轻松地构建您的下一个应用程序。 您的免费帐户永不过期,您将获得256 MB的Cloud Foundry运行时内存,以及2 GB的Kubernetes群集。 获取所有详细信息,并了解如何开始。 如果您是IBM Cloud的新手,请在developerWorks上查看IBM Cloud Essentials课程

 相关资料
  • Angular MDC NOTE: The Angular Components team at Google is working to deliver officially supported API-compatible versions of the Angular Material components backed by MDC Web. Follow the effort here

  • Nativescript Angular Web Starter A simple starter project to create native mobile and web apps with single shared code base using angular and nativescript. Check this Open Souce Cross Platform Quotes

  • Spring boot app with Angular 5 client embedded       Please donate whether you wish support us to give more time to app's growth, or buy the restaurant web app The frontend-app is extended from the in

  • 我一直在想方设法为angular2、sass和ng2引导建立一个基础项目,该项目基于angular2种子项目,您可以在这里找到整个代码库:https://github.com/omargon/angular-seed-sass-ng2-bootstrap对于dev和prod发行版,所有内容都按预期进行了构建。但是,每当我尝试运行uni和e2e测试时,总是会出现以下错误: 欢迎任何帮助。

  • 本文向大家介绍基于豆瓣API+Angular开发的web App,包括了基于豆瓣API+Angular开发的web App的使用技巧和注意事项,需要的朋友参考一下 一、扯淡的说 name:【豆瓣搜索】 最近关注了下豆瓣的API,发现豆瓣开放平台需要加强API文档撰写啊....但是有个可喜的发现豆瓣V2接口提供了搜索接口。最近在用phantom弄些爬虫,想想,真是美丽极了!有个豆瓣的接口,我都不用去