2016-04-21 68 views
0

我正在同時學習Angular 1.5和js。我從notify.js中分配一些默認值。我有沒有錯誤的代碼,但我有一種感覺,如果可以以更好的方式完成。此外,只要我嘗試並把回報,我會得到錯誤。有人能告訴我做最好的辦法,如果其他人和回報去(底部或內聯?)。我仍然很難結束函數和分號。我知道這些看起來很奇怪,但沒有錯誤。其他如果和返回javascript

謝謝。

function NotificationService ($scope, $) { 
    var vm = this; 
    /** 
    * @see notifyjs.com 
    */ 
    vm.publish = function (type) { 
     if (type === 'info') { 
      $.notify.defaults({ 
       scope: $scope, 
       className: 'info', 
       autoHide: true, 
       position: 'bottom' 
      }); 
     } 

     else if (type === 'success') { 
      $.notify.defaults({ 
       scope: $scope, 
       className: 'success', 
       autoHide: true, 
       position: 'bottom' 
      }); 
     } 

     vm.publishNoClose = function() { 
      $.notify.defaults({ 
       scope: $scope, 
       className: 'warn', 
       autoHide: true, 
       position: 'bottom' 

      }); 
     }; 

     vm.publishNoCloseAlert = function() { 
      $.notify.defaults({ 
       scope: $scope, 
       className: 'error', 
       autoHide: false, 
       position: 'middle' 
      }); 
     }; 
    }; 
} 

回答

1

只要做到:

$.notify.defaults({ 
       scope: $scope, 
       className: type, 
       autoHide: true, 
       position: 'bottom' 
      }); 
     } 

他們分享一切,但類名。

+0

我明白了,每個人都會得到回報嗎? – CB1111

+0

你是什麼意思的「每個」? – TheDude

相關問題