mercredi 6 mai 2015

Why am I getting an Illegal Token error in my case statement boolean assignment?

I use the same syntax in other switch case statements which work. I basically create an empty object and start adding in key value pairs to it:

var vs = $scope;
vs.toggleTimeSpan = function(string) {

    vs.time.span = {};

    switch(string) {
        case '1h':
            // vs.time.span[1h] = true;
            vs.time.span.1h = true;
            break;

        case '1d':
            vs.time.span.1d = true;
            break;

        case '1m':
            vs.time.span.1mo = true;
            break;

        case '1y':
            vs.time.span.1yr = true;
            break;

        case 'max':
            vs.time.span.max = true;
            break;
    }
};

enter image description here

Here is where I intend on using the vs.time.span object:

<ul class="timescale">
    <li ng-class="{'active':time.span.1h}"
        ng-click="toggleTimeSpan('1h')">1 h</li>

    <li ng-class="{'active':time.span.1d}"
        ng-click="toggleTimeSpan('1d')">1 d</li>

    <li ng-class="{'active':time.span.1mo}"
        ng-click="toggleTimeSpan('1mo')">1 mo</li>

    <li ng-class="{'active':time.span.1yr}"
        ng-click="toggleTimeSpan('1yr')">1 yr</li>

    <li ng-class="{'active':time.span.max}"
        ng-click="toggleTimeSpan('max')">max</li>
</ul>

Aucun commentaire :

Enregistrer un commentaire