0

Directive

myApp.directive("progressingIndex", function ($compile, $rootScope, constant) {


     var linker = function (scope, element, attrs) {
     var Id = $rootScope.Obj.pictureId;

switch (Id) {
        case constant.picturebox00: $rootScope.Obj.progressing00 = true; break;
        case constant.picturebox01: $rootScope.Obj.progressing01 = true; break;
        case constant.picturebox02: $rootScope.Obj.progressing02 = true; break;
        case constant.picturebox03: $rootScope.Obj.progressing03 = true; break;
        case constant.picturebox10: $rootScope.Obj.progressing10 = true; break;
        case constant.picturebox11: $rootScope.Obj.progressing11 = true; break;
        case constant.picturebox12: $rootScope.Obj.progressing12 = true; break;
        case constant.picturebox13: $rootScope.Obj.progressing13 = true; break;
        case constant.picturebox20: $rootScope.Obj.progressing20 = true; break;
        case constant.picturebox21: $rootScope.Obj.progressing21 = true; break;
        case constant.picturebox22: $rootScope.Obj.progressing22 = true; break;
        case constant.picturebox23: $rootScope.Obj.progressing23 = true; break;
        case constant.picturebox30: $rootScope.Obj.progressing30 = true; break;
        case constant.picturebox31: $rootScope.Obj.progressing31 = true; break;
        case constant.picturebox32: $rootScope.Obj.progressing32 = true; break;
        case constant.picturebox33: $rootScope.Obj.progressing33 = true; break;
}

    $compile(element.contents())(scope);  
    };
    return {
        restrict: "E",
        link: linker
    };
});

Here var Id gives me value for 00,01, etc. How do I dynamically generate cases for switch statement by appending Id ?

1 Answer 1

1
switch(constant['picturebox'+Id]) {
    case constant['picturebox'+Id]: $rootScope.Obj['progressing'+Id] = true; break;
}

This is enough to test all cases.

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

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.