Validation AngularJS-如何在禁用的文本框中显示自定义文本
我有以下输入控件:Validation AngularJS-如何在禁用的文本框中显示自定义文本,validation,angularjs,Validation,Angularjs,我有以下输入控件: <input type="ng-model="someValue" ng-disabled="shouldBeDisabled"/> 您可以使用ng show/ng hide交换输入,如下所示: <input ng-model="disabledText" ng-show="shouldBeDisabled" disabled/> <input ng-model="someValue" ng-hide="shouldBeDisabled"
<input type="ng-model="someValue" ng-disabled="shouldBeDisabled"/>
您可以使用ng show/ng hide交换输入,如下所示:
<input ng-model="disabledText" ng-show="shouldBeDisabled" disabled/>
<input ng-model="someValue" ng-hide="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;
}
});
手表演示:我接受这个,因为它不需要复制元素。谢谢。或者,您可以在禁用span/div时在输入上覆盖一个span/div,并在其中显示禁用的文本,但通过javascript或使用两个输入非常简单。