简体   繁体   English

AngularJS:如何将复选框中的标签添加到div

[英]AngularJS: How to add label from checkbox to div

How can I send the text from selected checkbox to the div with selected-checkbox class? 如何将带有selected-checkbox类的文本从选定checkbox发送到div

For example, if I click on the first checkbox the div should get the text "First label". 例如,如果我单击第一个checkboxdiv应该获得文本“第一个标签”。

JSFIDDLE JSFIDDLE

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<label>First label</label>
<input type="checkbox" />

<label>Second label</label>
<input type="checkbox" />

<label>Third label</label>
<input type="checkbox" />

<div class="selected-checkbox"></div>

I updated a fiddle. 我更新了一个小提琴。 Please use below link https://jsfiddle.net/itsramesh/8jauzmtm/4/ 请使用以下链接https://jsfiddle.net/itsramesh/8jauzmtm/4/

Using angular ng-true-value attribute directive for checkboxes you can set label name to div. 对复选框使用ng-true-value属性角度指令,可以将标签名称设置为div。

在此处输入图片说明

<script> 
angular.module('myApp',[]);
angular.module('myApp',[]).controller('MyController',function($scope){
$scope.obj={};
})
</script>

<div ng-app="myApp" ng-controller="MyController">
<label>First label</label>
<input type="checkbox" ng-model="obj.first" ng-true-value="First label" ng-false-value=""/>

<label>Second label</label>
<input type="checkbox" ng-model="obj.first" ng-true-value="Second label" ng-false-value=""/>

<label>Third label</label>
<input type="checkbox" ng-model="obj.first" ng-true-value="Third label" ng-false-value=""/>

<div class="{{obj.first}}">{{obj.first}}</div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM