Niranjan Godbole
Niranjan Godbole

Reputation: 2175

switch case not getting control in angularjs?

Hi I am developing angularjs application. I have one dropdown with month values. I have another textbox with calender. If i select two months from dropdown then i want to add 60 days to current date and i want to restrict the user to select next 60 days. For example today 14 so if i select 2 months from dropodwn then user can select date from calender after two months.

$scope.editCalender = function (period)
{
    //period 1,2,3,4,5,6
    var dayvalue;
    switch (period) {
        case '1':
            dayvalue ==30;
            break;
        case '2':
            dayvalue == 60;
            break;
        case '3':
            dayvalue = 90;
            break;
        case '4':
            dayvalue = 120;
            break;
        case '5':
            dayvalue = 150;
            break;
        case '6':
            dayvalue = 180;
            break;
        default:

    }

    var CurrentDate = new Date();
    CurrentDate.setMonth(CurrentDate.getDay() + dayvalue );
    console.log(CurrentDate.toLocaleDateString());
    $scope.maxdate = CurrentDate.toLocaleDateString();
}

This is how i assign set value using date-min-limit="{{maxdate}}". In the above code if i select 2 months then dayvalue == 60; but i am getting undefined. May i get some help to fix this issue! Any help would be greatly appreciated. Thank you.

Upvotes: 0

Views: 32

Answers (1)

Jigar Shah
Jigar Shah

Reputation: 6223

For int value case should be like this:

switch (period) {
    case 1: 
        dayvalue =30;
        break;
    case 2:
        dayvalue = 60;
        break;
    case 3:
        dayvalue = 90;
        break;
    case 4:
        dayvalue = 120;
        break;
    case 5:
        dayvalue = 150;
        break;
    case 6:
        dayvalue = 180;
        break;
    default:

}

'' should be used with string values

Upvotes: 1

Related Questions