您可以通過以下做到這一點,雖然你可能想把手錶放在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
我接受這一個,因爲它不需要元素的重複。 – matra
謝謝。或者,您可以在禁用時在輸入上覆蓋span/div,並在其中顯示禁用的文本,但通過javascript或兩個輸入非常簡單。 – lucuma