根据ngDialog open中的条件应用css

Apply css based on condition in ngDialog open

本文关键字:条件 应用 css ngDialog open 根据      更新时间:2023-09-26

如何应用基于条件isErroredtruefalse的类

下面的代码不能工作:

$scope.addWork = function() {
    var isErrored = false;
    $rootScope.$on('isErrored', function(event, data) { 
        alert(data);
        if(data == true)
            isErrored = true;
    });
    ngDialog.open({
        scope: $scope,
        template: 'addWorkingDialog',
        controller: 'addWorkingController',
        className: isErrored ? 'ngdialog-theme-default 
         alertmsgDialog' : 'ngdialog-theme-default workingDialog'
    });
};

您应该将$rootScope.$on('isErrored', function(event, data) { ... });移出$scope.addWork函数,因为它是一个事件侦听器,然后使用isErrored作为$scope属性。

$scope.isErrored = false;
$rootScope.$on('isErrored', function(event, data) { 
    if(data == true)
        $scope.isErrored = true;
    else
        $scope.isErrored = false;
});
$scope.addWork = function() {
    ngDialog.open({
        scope: $scope,
        template: 'addWorkingDialog',
        controller: 'addWorkingController',
        className: $scope.isErrored ? 'CLASS_1' : 'CLASS_2'
    });
};