2

I am trying to get the selected value from a dropdown menu. I always get the error of missing ng-model.

I tried to pass the selected value in the ng-click but it didn't work.

Here's my dropdown menu

<ul class="dropdown-menu">
      <li><a  href=""   ng-click="dropboxitemselected(xx)" >Cible</a></li>
      <li><a href="" ng-click="marque()">Marque</a></li>
      <li><a href="" ng-model="modele()">Modéle</a></li>
      <li><a href=""  ng-model="calculateur()">Calculateur</a></li>             
</ul>

And here my controller

$scope.dropboxitemselected = function (x) {
    alert(x);

}

I need the selected value as I am going to insert the value into an API then resend the data selected.

1
  • i think it should be binded in li tag Commented Apr 11, 2016 at 9:56

3 Answers 3

2

Its enough to change xx to 'cible' like this :

<ul class="dropdown-menu">
  <li><a  href=""   ng-click="dropboxitemselected('cible')" >Cible</a></li>
  <li><a href="" ng-click="marque()">Marque</a></li>
  <li><a href="" ng-model="modele()">Modéle</a></li>
  <li><a href=""  ng-model="calculateur()">Calculateur</a></li>             
</ul>

And you'll see an alert saying 'cible' on your page when clicked first link.

Dis moi si ça marché pour toi.

Sign up to request clarification or add additional context in comments.

Comments

1

If you need to know which of the items is selected you need to add ng-click="dropboxitemselected('POINT_NAME_HERE')" to each of them:

<ul class="dropdown-menu">
  <li><a href="" ng-click="dropboxitemselected('cible')">Cible</a></li>
  <li><a href="" ng-click="dropboxitemselected('Marque')">Marque</a></li>
  <li><a href="" ng-click="dropboxitemselected('Modéle')">Modéle</a></li>
  <li><a href="" ng-click="dropboxitemselected('Calculateur')">Calculateur</a></li>             
</ul>

Aside from that, ngModel, is something different from click event handler.

Comments

0

Just add quotes if you are willing to send a static value, else send a scope varibale.

<div ng-controller="Ctrl" >
    <ul class="dropdown-menu">
      <li><a  href=""   ng-click="dropboxitemselected('xx')" >Cible</a></li>
      <li><a href="" ng-click="marque()">Marque</a></li>
      <li><a href="" ng-model="modele()">Modéle</a></li>
      <li><a href=""  ng-model="calculateur()">Calculateur</a></li>             
</ul>
<div>

JsFiddle : http://jsfiddle.net/t6ncvg5w/

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.