0

如何根据条件申请类isErroredtrueor false

以下代码不起作用:

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

1 回答 1

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'
    });
};
于 2015-06-02T12:20:02.407 回答