0

I am newbie to Angular js.'this' operator will be helpful, but no idea how to use it.

On Each First Column, user will input the data, and corresponding that data should be fetched. Now data is fetched from php to Angular js, but how to push the data from angular js to that text box using "this" operator.

For eg: If 'Y' is entered then, X and Z should be push to textbox If 'Q' is entered then, P and R should be push to textbox. HTML:

<tr>
    <td><input type="text" ng-model="bot.Wo_Id" /></td>
    <td><input type="text" ng-click="acc1()" ng-value="b_code" /</td>
        <td><input type="text" ng-value="Pre_req" /></td>
        <td><a href ng-click="remove_bottle(bottle)">Remove</a></td>
</tr>
<tr>
    <td><a href ng-click="add_bottle()">Add</a></td>
</tr>

Angular Js:

$scope.acc1 = function () {
    $http.get("machin.php", {
            params: {
                "W_id": this.bot.Wo_Id,
                "MC": "Machine"
            }
        })
        .success(function (response) {
            var values = response.split("@");
            $scope.b_code = ?
            $scope.Pre_req = ? // what should be code here
        });
};

machin.php

echo X."@".Z   //for input Y
echo P."@".R   //for input Q

I am unable to sort this problem.Please help me.Thanks in advance.

sam007
  • 13
  • 5
  • What do you want written into b_code and what do you want written into pre_req? Should b_code show X and pre_req show Z or? – Bergur May 17 '17 at 10:00
  • @Bergur Yes it is. – sam007 May 17 '17 at 10:18
  • Possible duplicate of [How does the "this" keyword work?](http://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work) – Liam May 17 '17 at 10:33

1 Answers1

1

This should do the trick:

  1. Don't use this, use $scope.
  2. Change ng-value to ng-model

HTML

<tr>
    <td><input type="text" ng-model="bot.Wo_Id" /></td>
    <td><input type="text" ng-click="acc1()" ng-model="b_code" /</td>
        <td><input type="text" ng-model="Pre_req" /></td>
        <td><a href ng-click="remove_bottle(bottle)">Remove</a></td>
</tr>
<tr>
    <td><a href ng-click="add_bottle()">Add</a></td>
</tr>

Angular:

$scope.acc1 = function () {
    $http.get("machin.php", {
            params: {
                "W_id": $scope.bot.Wo_Id,
                "MC": "Machine"
            }
        })
        .success(function (response) {
            var values = response.split("@");
            $scope.b_code = values[0];
            $scope.Pre_req = values[1];
        });
    };

Here's a plunker with example. I can't do the http request so I just resolve the promise.

https://plnkr.co/edit/f6EzxBlaFInJghNwsXaU?p=preview

Bergur
  • 2,668
  • 8
  • 15
  • Thanks, but its not what I am expecting. In each row, if you enter Y then it show X and Z, if you enter Q in second row then it should show P and R.Now on second row also its showing the X and Z. – sam007 May 17 '17 at 10:44