저는 angular js를 처음 접했고 작업을 업데이트 할 수있는 간단한 할일 목록 응용 프로그램을 작성하려고합니다. 편집 버튼을 클릭 할 때마다 텍스트 상자를 편집 할 수 있고 HTTP 요청을 통해 서버에 새 값을 보내지 만 angular js에서 새 값을 가져올 수 없습니다.
내 HTML 코드는 다음과 같습니다.
<tr data-ng-repeat="user in tasks.tasks">
<td> // user.uid // </td>
<td > <input type="text" id="ddd" name="updatedText" ng-model="user.taskname" ng-disabled="!disable" value="//user.taskname//">
<input type="image" ng-hide="okbtnstatus" ng-click="updateIt()" src="static/img/okbtn.png" height="15px" width="18px" name="editId" value="//user.uid//">
내 Angular 코드는 다음과 같습니다.
$scope.updateIt = function(){
var data = $scope.user.taskname
alert(data)
$http({
method: "PUT",
url:"item/"+data
}).then(function mySuccess(response){
alert("Updated!!!")
},
function myError(response){
alert("error occurred")
});
}
여기에서는 데이터 변수에서 업데이트 된 값을 얻지 못했습니다. 도와주세요.
코드 $scope.user
에서 설정되는 위치를 볼 수 없지만 확실히 선택된 user
.
<tr data-ng-repeat="user in tasks.tasks">
<td> // user.uid // </td>
<td> <input type="button" ng-click="updateIt(user)" value="//user.uid//"/> </td>
</tr>
이 함수는 사용자를받습니다.
$scope.updateIt = function(user){
var data = user.taskname;
alert(data);
}
우리가 사용하는 함수 내에서을 var data = user.taskname;
사용 $scope.user.taskname
하면 $scope.user
설정 위치를 볼 수 없기 때문에 예기치 않은 결과 가 발생합니다.
올바른 길로가는 데 도움이되기를 바랍니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다