1
我需要爲我的項目使用合適的警告和助手,並發現角度材質很棒。但是,不要在每個控制器中粘貼幾行,因爲我需要重新使用它們。可重複使用的角度材料對話框和信息助手和警報的烤麪包
我需要爲我的項目使用合適的警告和助手,並發現角度材質很棒。但是,不要在每個控制器中粘貼幾行,因爲我需要重新使用它們。可重複使用的角度材料對話框和信息助手和警報的烤麪包
我需要將它們設置爲工廠,以便我可以從任何控制器調用它們。我發現他們非常有用可能對某人有用。
警報
(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));
};
}]);
})();
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);
};
}]);
})();
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 }
}
showAlert( '警報名稱在這兒', '這是警報消息主體中。',EV);應該是showAlert('Alert Title Goes Here','這是警告消息正文',event); – tfa