Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am Working on this task from 2 days , i am trying to push unique id object into array but it is not working and css also not working for selection and deselection. Here my code below

HTML :

 <li><a href=""  ng-class="{'activeQuestion' :active}"  ng-click="selectAnswer('{{ans.choiceID}}')"><choicecontentdesc></choicecontentdesc></a></li>

CSS:

#questionFullWidthPanel #questionRight nav li .activeQuestion {
//background: url(../img/ico/checked.png) !important;
background-repeat: no-repeat !important;
background-position: 90% center !important;
background-color: #ececec; !important;
//border-top: 1px solid #b9db92;
//border-bottom: 1px solid #b9db92;
color: #81be4a !important;
font-family: "proxima_nova_rgbold" !important
}

Directive:

   scope.$parent.$parent.$parent.$parent.selected=[];

      scope.selectAnswer = function () {
        //alert(scope.id);
        if (scope.ansSubmitted) {
          return;
        }

     console.log("posssss",scope.$parent.$parent.$parent.$parent.selected.indexOf(scope.id));
        scope.$parent.$parent.$parent.$parent.selectedObj = {
         'selectedChoiceId' : scope.id,
         'selectedChoiceDesc' : scope.text
          };
console.log("obj",scope.$parent.$parent.$parent.$parent.selectedObj);

        scope.active = scope.id === scope.$parent.$parent.$parent.$parent.selectedObj.selectedChoiceId;

 var pos = scope.$parent.$parent.$parent.$parent.selected.indexOf(scope.id);
        console.log("pos",pos);
        if (pos == -1) {
          scope.$parent.$parent.$parent.$parent.selected.push({
            id:      scope.$parent.$parent.$parent.$parent.selectedObj.selectedChoiceId,
            text: scope.$parent.$parent.$parent.$parent.selectedObj.selectedChoiceDesc,
            //datecolor:$scope.color
          })
            console.log("array1",scope.$parent.$parent.$parent.$parent.selected);
        } else {
          scope.$parent.$parent.$parent.$parent.selected.splice(pos, 1);
        }

Does anyone know how to implement it??

share|improve this question
    
Create a Fiddle please... – The Dark Knight Oct 28 '15 at 7:51
    
Is your <li> within ng-repeat? – Kulbhushan Oct 28 '15 at 7:52
    
hi kulbhushan ,yes <li> is within ng-repeat . – Vikas Oct 28 '15 at 7:53
    
then you can pass $$hasKey property which is always unique and added by Angular, ng-click="selectAnswer(ans.$$hasKey)". – Kulbhushan Oct 28 '15 at 8:07
    
It's missing too much information, first dont use brace in ng-click selectAnswer('{{ans.choiceID}}') -> selectAnswer(ans.choiceID). Then use the parameter you send to selectAnswer inside your controller. – ThibaudL Oct 28 '15 at 8:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.