2015-11-04 41 views
0

在角材料fullstack约曼发电机采用了棱角分明材料,我结合了toast方式来处理在控制了大量的外来代码

var last = { 
    bottom: false, 
    top: true, 
    left: false, 
    right: true 
}; 

$scope.toastPosition = angular.extend({},last); 

function sanitizePosition() { 
    var current = $scope.toastPosition; 
    if (current.bottom && last.top) current.top = false; 
    if (current.top && last.bottom) current.bottom = false; 
    if (current.right && last.left) current.left = false; 
    if (current.left && last.right) current.right = false; 
    last = angular.extend({},current); 
} 

$scope.getToastPosition = function() { 
    sanitizePosition(); 
    return Object.keys($scope.toastPosition) 
    .filter(function(pos) { return $scope.toastPosition[pos]; }) 
    .join(' '); 
}; 

var showSimpleToast = function() { 
    $mdToast.show(
    $mdToast.simple() 
     .content('Please enter a valid stock name.') 
     .position($scope.getToastPosition()) 
     .hideDelay(3000) 
); 
}; 

我能做出来“获取验证码的方式'?它值得实施到服务中吗?我根本不希望它占用我的控制器中的太多空间。

+0

将您的吐司逻辑移至工厂。 – levi

+0

好,无论是为了自己的目的而包装的指令,还是在工厂中拥有逻辑,并从指令或控制器调用以加载烤面包......取决于你将如何使用它以及在哪里......我将它作为指令使用,因为它操纵DOM并从工厂 –

+1

调用添加删除功能,这是一个很有见地的问题。很多可能的答案。 – cgTag

回答

0

对不起,如果我误解了你的问题,但你在找这个吗?

$mdToast.show(
    $mdToast.simple() 
    .content('Please enter a valid stock name.') 
    .position('top right') 
    .hideDelay(3000); 
); 

他们拥有的额外代码只是让您无法检查两个相对的复选框或缺少方向,例如, top bottom失去bottom并获得默认的方向。

相关问题