1

Angular のリアルタイム メッセージング アプリケーションがあり、HTML5 通知を使用したいと考えていました。コントローラー内で次のことを試しました。

$rootScope.$on("message_recieved", function(event, data) {
  new Notification(data.sender_name, {
    body: data.body, icon: data.avatar, dir:'auto'
  });
}

$rootScope.$on("server_offline", function(event, data) {
  new Notification("Offline", {
    body: "You are offline. Refresh your page now.", dir:'auto'
  });
}

通知が表示されません。私はここで何か悪いことをしていますか?

4

1 に答える 1

1

通知の表示が許可されていない可能性があります。許可をリクエストできます:

$rootScope.$on( 'message_received', function(event, data){
     Notification.requestPermission(function (permission){
          if (permission === "granted"){
               new Notification(data.sender_name, {
                    body: data.body, icon: data.avatar, dir:'auto'
               })
          }
      })
 })

src - https://developer.mozilla.org/en-US/docs/Web/API/notification

于 2015-12-15T17:04:35.783 に答える