3

I've been tinkering around with a bit of code in AngularJS. I ran into a slight problem. I would like the user to select from 3 options... (Look below for my HTML for )

<label class="item item-input item-select">
    <div class="input-label">
        Frequentie
    </div>
    <select name="multipleSelect" id="multipleSelect" ng-model="data.multipleSelect">
        <option value="eenmalig" >Eenmalig</option>
        <option value="maandelijks">Maandelijks</option>
        <option value="wekelijks">Wekelijks</option>
    </select>
</label>

On request the code for the activating button:

<div class="bar ">
    <input type="button"
           ng-click=addToNgRepeatMinus("uitgiften");startAgain()
           value="uitgaven"
           class="button button-dark"
           id="uitgiftenbutton">

    <input type="button"
           ng-click=addToNgRepeatPlus("inkomsten");startAgain()
           value="inkomsten"
           class="button button-dark"
           id="inkomstenbutton">
</div>   

Now my general understanding was that I could let certain things happen depending on which statement they would choose to select. (Which I am sure you can, but I just can't atm!)

first, I tried to use if, if else and else for it.. but I discovered that the if else statement isn't available in AngularJS.(Please correct me if it is!)

So naturally, I tried to use a switch.. which doesn't work sadly!

$scope.addToNgRepeatMinus = function(data) {
    if(data === "uitgiften"){
        switch(multipleSelect) {
            case "eenmalig":
                $scope.uitgiften.push({name: $scope.formulier.name,value: $scope.formulier.value});
                break;
            case "maandelijks":
                $scope.uitgiften.push({name: $scope.formulier.name,value: $scope.formulier.value});
                break;
            case "wekelijks":
                $scope.uitgiften.push({name: $scope.formulier.name,value: 4*$scope.formulier.value});
                break;
        }
    }
};

This bit of code also interacts with certain buttons. (The function addToNgRepeatMinus gets activated when these buttons get pressed.) So when I press the button, It checks if the incoming data equals "uitgiften". If it does so, It should know that data.multipleSelect would equals either "eenmalig", "wekelijks" or "maandelijks" and then do the correct thing.

Can someone help me with this? What am I doing wrong ? :)

2
  • How are you calling addToNgRepeatMinus function? Commented Dec 14, 2015 at 10:15
  • I'll edit my code. I'll add the buttons which activate addToNgRepeatMinus|| edited in the original post 11:20 Commented Dec 14, 2015 at 10:18

2 Answers 2

2

As your dropdown(select) is mapped to data.multipleSelect ng-model so when you do select ng-model="data.multipleSelect", you are binding your select to $scope.data.multipleSelect.

So, inside your controller, if you want to have an access your selected value, you use the following : $scope.data.multipleSelect

$scope.addToNgRepeatMinus = function(data) {
  if(data === "uitgiften"){
  switch($scope.data.multipleSelect) {
    case "eenmalig":
      $scope.uitgiften.push({name: $scope.formulier.name,value: $scope.formulier.value});
    break;
    case "maandelijks":
      $scope.uitgiften.push({name: $scope.formulier.name,value: $scope.formulier.value});
    break;
    case "wekelijks":
      $scope.uitgiften.push({name: $scope.formulier.name,value: 4*$scope.formulier.value});
    break;
  }
}
};
Sign up to request clarification or add additional context in comments.

Comments

1

From the code you have shown, you should use switch($scope.data.multipleSelect)

If that doesn't work you need to provide some more code.

2 Comments

I'll try that. If it doesn't I'll bury you in some code :D Thank you for the reply
It worked. thank you alot! Been busy with it for 1,5 hours and it was just a simple mistake -.- Thank you so much

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.