当我更新"item.MaxLength“值时,它不会影响输出,仍然将原始值显示为md-maxlength。我的代码出了什么问题?谢谢。
Input-1:我希望它将md-maxlength值改为"input-2“
<input type="text" ng-model="item.Desc" md-maxlength="{{item.MaxLength}}">Input-2:我想用-1\f25 "item.MaxLength“控制输入-1\f25 md-1\f6的最大长度。
<input type="number" ng-model="item.MaxLength">发布于 2017-07-27 04:42:31
显然,几乎没有办法动态更新md-maxlength的值。但是你的问题还是有解决办法的。更改长度设置字段的值后,只需删除并重新渲染输入元素即可。在md-input-container上添加ng-if &通过使用$watch或对长度字段使用ng-change函数在长度字段中相应地更改其值。
<md-input-container ng-if="showN">
<label>Name</label>
<input type="text" md-maxlength='{{view.len}}' ng-model="view.name" />
</md-input-container>
<md-input-container>
<label>Len</label>
<input type="number" ng-model="view.len" />
</md-input-container>在控制器中有:
$scope.$watch('view.len', function(n,o){
$scope.showN = false;
$timeout(function(){
$scope.showN = true;
});
});https://stackoverflow.com/questions/45334407
复制相似问题