尽管您可能想戴上手表,但您可以通过以下方式做到这一点shouldBeDisabled
;
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.shouldBeDisabled = true;
$scope.toggleIt = function() {
$scope.shouldBeDisabled= ! $scope.shouldBeDisabled;
$scope.someValue= $scope.shouldBeDisabled && $scope.disabledText || "true value"; // modify as required or leave off the true part.
}
});
您还可以存储该值,以便当禁用的文本出现然后切换回来时,您可以重新填充它。这是带手表的。
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.shouldBeDisabled = true;
$scope.disabledText = 'disabled stuff';
$scope.maintainTrueValue = '';
$scope.$watch('shouldBeDisabled', function() {
if ($scope.shouldBeDisabled)
$scope.maintainTrueValue = $scope.someValue;
$scope.someValue= $scope.shouldBeDisabled && $scope.disabledText || $scope.maintainTrueValue;
});
$scope.toggleIt = function() {
$scope.shouldBeDisabled= ! $scope.shouldBeDisabled;
}
});
带手表的演示: http ://plnkr.co/edit/8KAJc9JXvi2rffsjPXF5?p=preview