admin管理员组

文章数量:1415460

<tr class="labels">
    <td nowrap="nowrap">Address</td>
    <td nowrap="nowrap"><label for="tbAddress"></label>
        <textarea name="tbAddress" id="tbAddress" cols="39" rows="5" ng-model="$parent.tbAddress"></textarea>

    </td>

</tr>
<tr>
    <td>&nbsp;</td>
    <td align="right">
        <input type="submit" name="button" id="button" value="Submit Record" class="btns" />
        <input type="reset" name="button2" id="button2" value="Cancel" class="btns" />
    </td>
</tr>

I'm not be able to get textarea value using AngularJS. All the input text fields are getting through the controller except the textarea. What am I doing wrong ?

alert($scope.tbAddress);
var thisData = {
    'name': $scope.tbFN,
    'pany': $scope.tbCompany,
    'designation': $scope.tbDesignation,
    'email': $scope.tbEmail,
    'phone': $scope.tbPhone,
    'mobile': $scope.tbMobile,
    'address': $scope.tbAddress
};

It's alert undefined...

<tr class="labels">
    <td nowrap="nowrap">Address</td>
    <td nowrap="nowrap"><label for="tbAddress"></label>
        <textarea name="tbAddress" id="tbAddress" cols="39" rows="5" ng-model="$parent.tbAddress"></textarea>

    </td>

</tr>
<tr>
    <td>&nbsp;</td>
    <td align="right">
        <input type="submit" name="button" id="button" value="Submit Record" class="btns" />
        <input type="reset" name="button2" id="button2" value="Cancel" class="btns" />
    </td>
</tr>

I'm not be able to get textarea value using AngularJS. All the input text fields are getting through the controller except the textarea. What am I doing wrong ?

alert($scope.tbAddress);
var thisData = {
    'name': $scope.tbFN,
    'pany': $scope.tbCompany,
    'designation': $scope.tbDesignation,
    'email': $scope.tbEmail,
    'phone': $scope.tbPhone,
    'mobile': $scope.tbMobile,
    'address': $scope.tbAddress
};

It's alert undefined...

Share Improve this question edited Apr 25, 2014 at 14:49 EnigmaRM 7,63211 gold badges48 silver badges74 bronze badges asked Apr 25, 2014 at 13:33 TariqTariq 1555 silver badges21 bronze badges 2
  • Have you tried alert($scope.$parent.tbAddress); ? What do you get ? – gkalpak Commented Apr 25, 2014 at 13:40
  • What is the scope context of your template? Are you using it in an ngInclude (judging by the $parent, you're either using that or perhaps a directive with isolate scope). Make sure the $scope var is actually the same in your controller as $parent in your template. – mingos Commented Apr 25, 2014 at 13:50
Add a ment  | 

1 Answer 1

Reset to default 6

If you have alert($scope.tbAddress); positioned right there, of course it'll end up as undefined. Nothing has been assigned to $scope.tbaddress at this point. (but maybe you have it defined earlier, but it's just not being shown in the code).

I actually didn't have a problem getting it to work. I wrapped the alert in a function that is bound to the submit button. I'm able to get the value. See my example.

I also took the liberty of changing your $scope a bit. It's remended that every ngModel has a . in it's name. So rather than tbAddress it should be tb.address. It has to do with how angular inheritance is handled.

Refer to:

  • Why don't the AngularJS docs use a dot in the model directive?
  • The Dot - egghead video
  • Google results for 'angular use dots in models'

本文标签: javascriptcan39t getting textarea value using AngularJsStack Overflow