7

我正在尝试将网络通知放到我的网站上,以便当我在我的网站中添加任何新项目时,我的所有客户都会在浏览器中看到我的通知。

我选择了angular-web-notification,我通过 Bower 在我的应用程序中安装并在本地进行了测试,它运行良好,但是当我将我的网站部署到生产环境时,然后我再次在生产环境中进行测试,通知仅在我的浏览器中出现,仅不适用于所有允许我的网站通知的客户。

这是我的代码:

.directive('showButton', ['webNotification', function (webNotification) {
  return {
    restrict: 'C',
    scope: {
      notificationTitle: '=',
      notificationMsg: '=',
      notificationUrl: '='
    },
    link: function (scope, element) {
      console.log("coming to directive notifications")
      element.on('click', function onClick() {
        console.log("coming to directive notifications click")

        if ((scope.notificationTitle) && (scope.notificationMsg)) {       

          webNotification.showNotification(scope.notificationTitle, {
            body: scope.notificationMsg,
            icon: 'https://lh3.googleusercontent.com/BCOE0vqCfr8aqpIKEF7QEt-qa7p8I7KDg58Juz6M6_YGb4l7phrO2vMvi_SDy10ucQ=w300',
            onClick: function onNotificationClicked() {
              console.log('Notification clicked.');
              window.open(scope.notificationUrl, '_blank')
            },
            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);
            }
          });
        }
      });
    }
  };
}]);
4

0 回答 0