0

I'm trying to implement search method for "chat channels" that for every query it represents the compatible results from SQL table from the database.Each result can be distinguished by a unique ID that is also comes from the SQl table.I don't want to show the ID's so I put them in a hidden input for each result using ng-model.Also, for each, result the user have a possibility to subscribe to the channel (subscribe button) displayed in this result,so in order to save the subscription properly,I need to get the ID saved in the hidden input of the same result.

Here's what I tried:

<table class="table table-condensed">
    <tr class="separating_line" ng-repeat="x in result">
        <!-- ng-bind-html allows to bind a variable to the innerHTML part of the HTML element -->
        <td>
           <div class="col-md-8">
             <h4><b style="color: gray;">{{ x.Name }}</b></h4>
             <br><p> {{ x.Description }}</p>
           </div>
           <div class="col-md-2">
             <small><label style="color: gray;">Subscribers </label>{{ x.Subscribersnum }}</label></small><br> 
             <input id="hiddenId" hidden="hide" ng-model="idval=x.ChanID" />
             <button ng-click="subscribechannel()" class="btn btn-primary">Subscribe</button>
           </div>
       </td>
   </tr>
</table>

In the controller I send it in the following way to convenient Servlet:

$http.get("http://localhost:8080/ExampleServletv3/subscribeservlet",{
        params: {
            subidval: $scope.idval
        }
})

But when debugging the value that I get in the servlet is null.

How can I solve this? Any ideas?

Thanks

2
  • There is no reason to use hidden fields in an Angular application: you're never submitting forms. Always sending AJAX requests. Just store data in variables of your controller. And BTW, ng-model doesn't expect a statement which assigns a value to a variable. Read the docuentation about ng-model (although, I repeat, you don't need it here). Commented Feb 19, 2017 at 8:11
  • but I need specific result value ,how can I do that? Commented Feb 19, 2017 at 8:12

1 Answer 1

2

You don't need any hidden field to do what you want. All you need is to pass a parameter to your function:

 <tr class="separating_line" ng-repeat="x in result">
     ...
     <button ng-click="subscribechannel(x)" class="btn btn-primary">Subscribe</button>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.