저는 기능에 익숙하지 않은 작은 코드에서 각도가 생겼습니다. - 1. 사용자의 선택에 따라 세부 정보를 추가할지 여부 예 또는 아니오 (라디오 단추)를 클릭하여 선택할 수 있습니다. 2. 예를 클릭하면 양식에 입력 된 데이터의 빈 텍스트 필드가 표시됩니다. 3. 필요한 경우 추가 텍스트 필드를 추가하거나 제거하기위한 버튼이 있습니다.angularJS에서 내 라디오 버튼이 제대로 작동하지 않습니다
매번 예와 아니요 사이를 전환하려고 할 때 더 많은 텍스트 필드가 생성되어 발생하지 않아야하며 추가 버튼을 클릭해야만 발생한다는 문제가 있습니다. ng-repeat 기능을 비활성화하면 예 또는 아니오 라디오 버튼을 토글 할 때 추가 텍스트 필드가 표시되지 않지만 필드를 추가 또는 제거하는 버튼은 작동하지 않습니다. 내가 실수를하고있는 곳에서 나는 우둔합니다.
내 index.html 파일
var app = angular.module("myWorld", []);
app.controller('msCtrl', myWorldMain);
function myWorldMain() {
$scope.worldClicked = function() { \t \t \t
if(angular.isUndefined($scope.peopleList)){
$scope.peopleList = [];
}
$scope.addPeopleRow();
}
$scope.addPeopleRow = function(){
\t \t \t // maximum is 20(0-19)
\t \t \t if (0 <= $scope.peopleList.length && $scope.peopleList.length < 20) {
\t \t \t \t $scope.peopleList.push({"checkBox":false,"customerid":"","organizationname":""});
\t \t \t \t
// \t \t \t \t \t
\t \t \t } else {
\t \t \t \t var msg = {error: $window.getCurrentContext().translateItemInstant("MyVar")};
\t \t \t \t alert(msg.error);
\t \t \t }
}
$scope.removePeopleRow = function(){
\t \t \t var len=$scope.peopleList.length;
\t \t \t var selectedRecords=[];
\t \t \t for(var i=0; i<len; i++){
\t \t \t \t if($scope.peopleList[i].checkBox){
\t \t \t \t \t selectedRecords.push($scope.peopleList[i]);
\t \t \t \t }
\t \t \t }
\t \t \t if(selectedRecords.length > 0){
\t \t \t \t for(j=$scope.peopleList.length-1; j>=0; j--){
\t \t \t \t \t if($scope.peopleList[j].checkBox){
\t \t \t \t \t \t $scope.peopleList.splice(j,1);
\t \t \t \t \t }
\t \t \t \t } \t \t \t \t
\t \t \t } else {
\t \t \t \t var msg = {error: $window.getCurrentContext().translateItemInstant($translate,"MyMesg)};
\t \t \t \t alert(msg.error);
\t \t \t \t return;
\t \t \t }
\t \t }
}
}
<!DOCTYPE html>
<html data-ng-app="myWorld">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js"></script>
</head>
<body ng-controller="msCtrl as moctrl">
<div>
<fieldset>
<span>
<input type="radio" data-ng-model="msCtrl.radio" title="My World" value="Y" data-ng-click="worldClicked()" id="myWorldradioYes"><label for="myWorldradioYes"> Yes</label>
<input type="radio" data-ng-model="msCtrl.radio" value="N" id="myWorldradioNo"><label for="myWorldradioYes">No</label>
</span>
</fieldset>
<br />
<div data-ng-if="myWorld.radio == 'Y'">
<table >
<thead>
<tr>
<th id="CheckBox" width="5%"></th>
<th id="custNumber" width="35%" translate="CustId"></th>
<th id="custLocation" width="60%" translate="Name_of_Organization"></th>
</tr>
</thead>
<tr data-ng-repeat="x in myWorldList">
<td align="left"><input type="checkbox" data-ng-model="x.checkBox" name="x.checkBox" value="x.checkBox"></td>
<td align="left"><label for="xcustid"/><input id="xcustid" type="text" name="x.custid" value="x.cusid" data-ng-model="x.cusid" maxlength="8" ng-class="x.custid.length>0 ? 'input-control focusedBlue':'input-control focusedRed'" required></td>
<td align="left"><label for="xorganizationname"/><input id="xorganizationname" name="x.organizationname" value="x.organizationname" type="text" size="50" data-ng-model="x.organizationname" maxlength="50" ng-class="x.organizationname.length>0 ? 'input-control focusedBlue':'input-control focusedRed'" required></td>
</tr>
<br/>
</table>
<div align="left" style="padding-left:25px">
\t
<button type="button" value="button" class="btn btn-success btn-s" href="JavaScript:void(0)" data-ng-click="addPeopleRow()">
<svg class="icon icon-circle-with-plus"><title>New party</title><use xlink:href="#icon-circle-with-plus"></use></svg>
<strong translate="New_Party"></strong> \t \t \t \t \t
</button>
<button type="button" value="button" class="btn btn-danger btn-s" href="JavaScript:void(0)" data-ng-click="removePeoplepRow()">
<svg class="icon icon-bin"><title>Remove party</title><use xlink:href="#icon-bin"></use></svg>
<strong translate="Remove_Party"></strong> \t \t \t \t \t
</button>
<br /> <br />
</div>
</div>
</div>
</body>
</html>
어떤'worldClicked은 (내가 코드에서 볼 수 없습니다)'는 무엇입니까? – sTx
코드를 편집했는지 확인하십시오. 감사. –