Prasanna Prasanna - 1 month ago 16
AngularJS Question

error getting the text box value in angular js

I am new to angular js, I am trying to write a simple todo list application in which I can update the task. whenever I click on edit button the text box enables for editing and I send a new value to the server via HTTP request but I can not get the new value in angular js .

Here is my HTML code:

<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//">

Here is my Angular code

$scope.updateIt = function(){

var data = $scope.user.taskname
method: "PUT",
}).then(function mySuccess(response){
function myError(response){
alert("error occurred")

Here I do not get the updated value in data variable. Please help.

Answer Source

We can not see where in your code $scope.user is being set, but definitely, this is going to show the selected 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>

The function will receive the user

$scope.updateIt = function(user){
    var data = user.taskname;

Inside the function we use var data = user.taskname;, using $scope.user.taskname will give unexpected result though, say that because we can't see where $scope.user is set.

Hope it helps get you on the right path.