0

Goal: On ng-repeat, initial 'isSelected' from array has icon. If any item is clicked after display, prior item isSelected= false and has icon removed, current item has isSelected=true and gets icon.

Current html:

<a data-ng-repeat="style in webStyles" id="{{style.id}}" data-ng-click="changeStyle(style.id)">
       <!-- only if item isSelected = true -->
                <i class="fa fa-check fa-fw" id="skin-checked"></i>
       <!-- end selected icon -->
    {{style.name}}
 </a>

The controller:

  1. changeStyle click event:

    $scope.changeStyle = function (style) {
        $scope.$emit('websiteStyleChange', style);
       // toDo: make all isSelected false, make item just clicked isSelected = true
    
    }; 
    
  2. data:

    $scope.webStyles = [
        { name: "Default", id: "style_0", isSelected: true},
        { name: "One", id: "style_1", isSelected: false},
        { name: "Two", id: "style_2", isSelected: false}
    ];
    

Any ideas?

Thanks ... .

1
  • Please mention in qquestion that What is the issue you are facing in this? Commented Mar 11, 2014 at 2:53

1 Answer 1

1

You can just loop through your webStyles after each click and set all isSelected to false except the one that was just clicked. For example...

$scope.changeStyle = function (style) {
    angular.forEach($scope.webStyles, function (value, key) {
        value.isSelected = value.id === style ? true : false;
    });
}; 

Then, to show/hide your icon, use the ng-show directive..

<i class="fa fa-check fa-fw" id="skin-checked" ng-show="style.isSelected"></i> 
Sign up to request clarification or add additional context in comments.

1 Comment

Strike my response above: Your solution works, but it is webStyles not webstyles

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.