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