2016-03-14 19 views

回答

3

我需要將它們設置爲工廠,以便我可以從任何控制器調用它們。我發現他們非常有用可能對某人有用。

警報

(function() { 
 
    'use strict'; 
 
    app.factory("showAlert", ["$mdDialog", function ($mdDialog) { 
 
     return function (title, content, ev) { 
 
      $mdDialog.show(
 
       $mdDialog.alert() 
 
       .parent(angular.element(document.querySelector('#popupContainer'))) 
 
       .clickOutsideToClose(true) 
 
       .title(title) 
 
       .textContent(content) 
 
       .ok('Ok') 
 
       .targetEvent(ev)); 
 
     }; 
 
    }]); 
 
})();

  1. 通過使工廠名 'showAlert' 到控制器從任何控制器調用。
  2. 確保您通過HTML中的'$ event',例如NG-點擊= 「的testAlert($事件)」
  3. 如下調用

app.controller('someController', showAlert) { 
 
    $scope.testAlert = function(event) 
 
    { 
 
     showAlert('Alert Title Goes Here', 'This is the alert message body.', ev); 
 
    } 
 
}


信息助手

(function() { 
 
    'use strict'; 
 
    app.factory("showHelper", ["$mdToast", "$timeout", function ($mdToast, $timeout) { 
 
     return function (content, startTime, duration) { 
 
      $timeout(function() { 
 
       $mdToast.show(
 
        $mdToast.simple() 
 
        .textContent(content) 
 
        .position('bottom left') 
 
        .hideDelay(duration * 1000) 
 
       ); 
 
      }, startTime * 1000); 
 
     }; 
 
    }]); 
 
})();

  1. 通過將工廠名稱'showHelper'傳遞給控制器​​從任何控制器調用。
  2. 傳遞消息,啓動助手的時間和結束助手的時間。
  3. 確保使用一個以上的助手時,下一個幫手計劃開始
  4. 我再乘以1000控制器
  5. 古稱用秒前以前的助手已經結束如下

app.controller('someController', showHelper) { 
 
\t $scope.testAlert = function() 
 
\t { 
 
\t \t showHelper('I am the first helper', 1, 4); 
 
\t \t showHelper('I am the second helper', 6, 2); 
 
\t } 
 
}

+1

showAlert( '警報名稱在這兒', '這是警報消息主體中。',EV);應該是showAlert('Alert Title Goes Here','這是警告消息正文',event); – tfa