在Angularjs中启用和禁用下拉式onchange textarea

时间:2018-12-11 04:51:05

标签: angularjs select onchange

这个问题已经问了,但是不能解决我的问题。

enable更改时,我想disabletext-area drop-down。我尝试了一些代码,但显示错误。

  

TypeError:无法设置未定义的属性“ disabled”   在Scope。$ scope.firstUsageChange(addcoupon.js:130)

addcoupon.html

<div class="col-sm-4">
    <label>First Usage<code>*</code></label>
    <select class="form-control" name="first_usage" ng-model="formData.first_usage" ng-change="firstUsageChange()" ng-required="true">
        <option value="">Select First Usage</option>
        <option value="yes">Yes</option>
        <option value="no">No</option>
    </select> 
</div>
<div class="col-sm-4">
    <label>First Usage Title<code>*</code></label>
    <textarea class="form-control" name="first_usage_title" ng-model="formData.first_usage_title"  ng-disabled="disabled" ng-required="true"></textarea>
</div>

addcoupon.js

$scope.firstUsageChange = function () {
    $scope.result = $scope.formData.first_usage;
    if($scope.result == 'yes')
    {
        $scope.first_usage_title.disabled= false;
    }
    else
    {
        $scope.first_usage_title.disabled= true;
    }
    //console.log();
};

2 个答案:

答案 0 :(得分:1)

在html部分:

<textarea class="form-control" name="first_usage_title" ng- 
model="formData.first_usage_title"  ng-disabled="disabled" ng-required="true"> 
</textarea>

尝试通过以下方式更改ng-disabled:

ng-disabled="first_usage_title.disabled"

答案 1 :(得分:0)

我得到的结果是我只更改了$ scope数据$scope.disabled = true;

$scope.firstUsageChange = function () {
    $scope.result = $scope.formData.first_usage;
    if($scope.result == 'yes')
    {
        $scope.disabled = true;
    }
    else
    {
        $scope.disabled = false;
    }
};