根据ngDialog open中的条件应用css

时间:2015-06-02 11:49:04

标签: javascript angularjs ng-dialog

如何根据条件isErrored将类应用为truefalse

以下代码无效:

$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'
    });
};

1 个答案:

答案 0 :(得分:0)

您应该将$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'
    });
};