角度 を使用して入力文字をカウントできるようにするには、文字数が60を超える場合は、代わりにテキストエリアを使用する必要があります。60文字を超える入力では、代わりにテキストエリアを使用する
私は私が私のスクリプトでこれをやって逃げることができるかもしれないと思った:
//my initial display value
$scope.display = "this is a particularly long string that i'm using to test this functionality";
//storing the length of the display variable
$scope.charCount = $scope.display.length;
私はその後、input
またはtextarea
を使用するかどうかを判断するためにng-if
状態にcharCount
変数を使用。
<div id="ctrl_{{field.id}}" ng-controller="controller" data-custom-focus="true" ng-if="charCount <= 60">
<input
type="text"
ng-bind="display"
ng-value="display">
</div>
<div id="ctrl_{{field.id}}" ng-controller="controller" data-custom-focus="true" ng-if="charCount > 60">
<textarea
type="text"
ng-bind="display"
ng-value="display" >
</textarea>
</div>
不思議なことに、どちらの要素もレンダリングされません。私はAngularのことをかなり新しくしているので、問題の内容がわからない。
? – trichetriche
それは働いています。ここを参照してください。両方の条件で同じコントローラを参照する必要があるため、https://plnkr.co/edit/Xq2D8brgN3WxMv10J6pm?p=preview –
@Satpalあなたがそれを感謝する良い方法を提案できるなら、私は角の専門家ではありません。 –