0

I have a list that shows some items, here is the code that generates my list in my controller:

$scope.multipleOptions = [{ item: '1', checkmark:false}, { item: '2', checkmark:false},{ item: '3', checkmark:false} ];

Then in my HTML I have

<ion-list id="multiple-select-list" class=" ">
         <ion-item class="  " ng-repeat="multipleOption in multipleOptions track by $index" ng-click="checkSelected($index)">
                <p><b>{{multipleOption.item}}</b></p>
                <p class="button-icon ion-checkmark" ng-show="{{multipleOption.checkmark}}"></p>
        </ion-item>
</ion-list>

As you can see when the list loads the checkmarks for all the items are hidden, and I have a function called checkSelected($index) that is called when an item is tapped, in that function I want to set the checkmark to be shown, here is what I currently have

$scope.checkSelected = function(modalIndex) {
        //this set the checkmark property to true
        $scope.multipleOptions[modalIndex].checkmark = true;
        //the line below does not work 
        document.getElementById("multipl-select-list").getElementsByTagName("ion-item")[modalIndex].getElementsByTagName("p")[1].show = true;
    }

In the above method I am able to set the checkmark variable of the item to ture but what I am having troubel with is making it show right when the item is tapped? How can I set the ng-show of the checkmark so it shows right when it is tapped?

EDIT Solutions both worked I just wanted to add some behabiour I noticed, when I had ng-show={{multipleOption.checkmark}} the ng-hide class would be added to the class of that <p> so even when I set ng-show to true it would still not be shown

Thanks for all the help

2 Answers 2

1

HTML :

<ion-list id="multiple-select-list" class=" ">
         <ion-item class="  " ng-repeat="multipleOption in multipleOptions track by $index" ng-click="checkSelected(multipleOption)">
                <p><b>{{multipleOption.item}}</b></p>
                <p class="button-icon ion-checkmark" ng-show="multipleOption.checkmark"></p>
        </ion-item>
</ion-list>

In javascript function :

$scope.checkSelected = function(data) {
    data.checkmark = true;
}
Sign up to request clarification or add additional context in comments.

5 Comments

thanks would you mind taking a look at the edit I added, just wondering why that would happed
@iqueqiorio - sorry, but i didn't get you, can you re-phrase it
when I originally had ng-show="{{multiple.checkmark}}" they when I went to that page in my browser and looked at this tag <p class="button-icon ion-checkmark" ng-show="multipleOption.checkmark"></p> in the browser it showed <p class="button-icon ion-checkmark ng-hide" ng-show="multipleOption.checkmark"></p> It added ng-hide to the class, so even when I manually changed the ng-show attribute to true it still was not shown, until I deleted ng-hide from the class attribute, make sense?
What do you mean you changed manually the ng-show attribute ? By the time you have ng-show="{{multiple.checkmark}}" it gets it as false so angular automatically adds ng-hide class.
@iqueqiorio - make sense? hmmm, not completely, but i am assuming you changing manually in browser (developer console/firebug); changing ng-show to true or false won't hide or show the element, adding/removing ng-hide from class will hide/show the element
1

I think the problem is with your syntax. Try removing curly brackets. Also take a look a this answer

ng-show="multipleOption.checkmark"

1 Comment

thanks would you mind taking a look at the edit I added, just wondering why that would happed

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.