1

I have dropdown list :

<select name="timefilter" id="timefilter">
 <option value="Last week">@Translate("LAST_WEEK")</option>
<option value="Last 3 days">@Translate("LAST_3_DAYS")</option>
 <option value="Yesterday">@Translate("YESTERDAY")</option>
<option value="Today">Translate("TODAY")</option>
</select>

I need to send value from dropdown list to $scope

  $scope.GetMenuForSelectedTime = function (numberOfDays) {
}

How can i do it?

EDIT: My function that i need to call:

   $scope.SelectTicketByTime = function (range) {

    var range = range;
    var date = new Date();
    var day = date.getUTCDate().padLeft();
    var monthIndex = (date.getUTCMonth() + 1).padLeft();
    var year = date.getUTCFullYear();
    var hours = date.getUTCHours().padLeft();
    var minutes = date.getUTCMinutes().padLeft();


    $scope.GetMenuForSelectedTime = function (numberOfDays) {


        var d = new Date();
        d.toUTCString();
        day = date.getUTCDate() - numberOfDays;
        day = day.padLeft();
        var offset = d.getTimezoneOffset();
        d.setHours(00);
        var hoursToAdd = offset / 60;
        d.setHours(hoursToAdd);

        if (day > daysInMonth(monthIndex, year)) {
            var dayOffset = day - daysInMonth(monthIndex, year);
            day = dayOffset.padLeft();

            monthIndex = (date.getUTCMonth() + 2).padLeft();
        }
        var To = year + monthIndex + day + d.getHours() + '00';

        $scope.to = To;

        $http.get(TicketUrl + 'GetTickets/0/0?DateFrom=' + $scope.from + '&DateTo=' + $scope.to).
        then(RecivedTickets, ErrorResponse);
    }





    if (range == "Today") {
        $scope.GetMenuForSelectedTime(0);
    }

    else if (range == "Yesterday") {
        $scope.GetMenuForSelectedTime(1);
    }
    else if (width == "Last 3 days") {
        $scope.GetMenuForSelectedTime(3);

    }  else if (width == "Last 7 days") {
        $scope.GetMenuForSelectedTime(7);

    }
2
  • Add ng-model to your select? Commented Jun 10, 2015 at 11:54
  • can u put an example ? Commented Jun 10, 2015 at 11:58

2 Answers 2

2

This is the example for putvande response (thanks to him):

<select name="timefilter" id="timefilter" ng-model="selectedTime">
 <option value="Last week">@Translate("LAST_WEEK")</option>
<option value="Last 3 days">@Translate("LAST_3_DAYS")</option>
 <option value="Yesterday">@Translate("YESTERDAY")</option>
<option value="Today">Translate("TODAY")</option>
</select>

And then you will have the value of your option in the controller :

$scope.selectedTime //The selected option

Edit : The function in your controller, will not need a value in param because the controller already know this value. You should have something like this.

$scope.SelectTicketByTime = function () {
    var range = $scope.selectedTime;
    var date = new Date();
    var day = date.getUTCDate().padLeft();
    var monthIndex = (date.getUTCMonth() + 1).padLeft();
    var year = date.getUTCFullYear();
    var hours = date.getUTCHours().padLeft();
    var minutes = date.getUTCMinutes().padLeft();
}
Sign up to request clarification or add additional context in comments.

5 Comments

When i change dropdown list nothing happend...i dont get any call
Did you try to print "selectedTime" ? What's his value ?
nothing...its not calling my function at all...i have function $scope.SelectTicketByTime = function (range) { } in controller where range is value from dropdown list
@None So do I to show how it works in your function.
0

I modify the code with ng-options and when you change any option in the dropdown, the ng-change will fire

<select name="ruleDetails" ng-model="selectedTime" 
  ng-options="time.id as time.value for time in timeDetails" 
  ng-change="GetMenuForSelectedTime(selectedTime)">
  <option value="">-Select Time-</option>
</select>

$scope.GetMenuForSelectedTime = function(id) {
    alert(id);
};

UPDATE:

This code also works, value will pass to the function.

<select name="timefilter" id="timefilter" 
  ng-model="selectedTime" 
  ng-change="GetMenuForSelectedTime(selectedTime)">
  <option value="Last week">@Translate("LAST_WEEK")</option>
  <option value="Last 3 days">@Translate("LAST_3_DAYS")</option>
  <option value="Yesterday">@Translate("YESTERDAY")</option>
  <option value="Today">Translate("TODAY")</option>
</select>

Please check this plunker

2 Comments

its good example just problem is that i need this dropdown list in mvc populated because im using @Translate function if u now what i mean?
The problem here is that the function getMenuForSelectedTime expect an number of day (int) and the value of the select are string.

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.