你好,我怀疑,
我有一个textarea来输入文本,还有一个单选按钮来选择一个选项。
如何显示以下内容:如果在textarea中键入内容(仅显示输入的文本),如果从单选按钮中选择一个选项,则删除textarea的内容并显示所选的单选按钮选项。 / p>
Jsbin基本示例:http://jsbin.com/pejufu/8/edit?html,js,output
感谢您的帮助!
答案 0 :(得分:0)
使用ng-change
根据您的逻辑设置最终结果:
<强> HTML 强>:
<textarea ng-model="text.text1" ng-change="setResult()" placeholder="Write here" style="min-width: 355px"></textarea>
<label ng-repeat="name in names" for="{{name}}">
{{name}}
<input type="radio" ng-model="my.favorite" ng-change="setResult()" ng-value="name" id="{{name}}" name="favorite">
</label>
<p>
Result or textarea or radio is: {{my.result}}
</p>
<强> JS 强>:
$scope.my = { favorite: '', result: '' };
$scope.checkResult = function () {
$scope.my.result = $scope.text.text1 ? $scope.text.text1 : $scope.my.favorite;
};