如何根据条件isErrored
将类应用为true
或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'
});
};
答案 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'
});
};