Mike
Mike

Reputation: 638

How to pass string parameters into ng-click

When I hard code in the value I want to pass like this, it works and data is being returned correctly:

<!-- This works! --> 
ng-click="LSCC.getCrawlResults(4661224)"

However, when I try to save a value from a text box and pass that into my ng-click, I am getting errors.

<!-- This doesn't work! -->
<input class="form-control" name="retailerID" ng-model"x">

<button type="button" class="btn btn-default" ng-click="LSCC.getCrawlResults('x')">Load</button>

I have tried passing parameters in a variety of different ways, but I can't seem to figure out how to accomplish this. Thank you!

Upvotes: 0

Views: 540

Answers (3)

Mike
Mike

Reputation: 638

To answer my question, I forgot an '=' sign.

ng-model"x"  <!-- No '=' sign -->

Upvotes: 0

Katie Barnes
Katie Barnes

Reputation: 36

Where is your ng-click function defined? In a controller? If so I would just attach everything to $scope and access the ng-model using $scope.x instead of trying to pass it in since that is giving you trouble

Upvotes: 1

BrTkCa
BrTkCa

Reputation: 4783

x is assign wrong in ng-model, and I guess it's necessary to remove the quotes.

<input class="form-control" name="retailerID" ng-model="x">

<button type="button" class="btn btn-default" ng-click="LSCC.getCrawlResults(x)">Load</button>

Upvotes: 1

Related Questions