1

I am new in AngularJS and try to do hide show in angularJs.

Below is my Code :

 <ul class="recent-rate-list">
 <li ng-repeat="ratedType in ratedTypes">
 <a href="#" style="line-height:30px">{{ratedType.type}}</a>
 </li>
 </ul>

AngularJS :

 $scope.ratedTypes = [
 {
 type: 'Select All',
 "value": '0',
 isSelected : true
 }, {
 type: 'Option 1',
 "value": '1',
 isSelected: false
 }, {
 type: 'Option 2',
 "value": '2',
 isSelected: false
 },{
 type: 'Option 3',
 "value": '3',
 isSelected: false
 },
 ];

Where I need when isSelected = true then

 <a href="#" style="line-height:30px"><span>{{ratedType.type}}</span></a>

and when isSelected = false then

 <a href="#" style="line-height:30px">{{ratedType.type}}</a>

I know angularJs has ng-if, but I unable to use it. How can I solve it using ng-if?

Thanks.

developer
601 silver badge12 bronze badges
asked Feb 3, 2017 at 7:07

2 Answers 2

2

You can put ng-if condition inside the div tag.

<div ng-if="isSelected === true"><a href="#" style="line-height:30px"><span>{{ratedType.type}}</span></a></div>
 <div ng-if="isSelected === false"><a href="#" style="line-height:30px">{{ratedType.type}}</a><div>

answered Feb 3, 2017 at 7:11
Sign up to request clarification or add additional context in comments.

Comments

0

You can rather add like this-

<div ng-if="isSelected"><a href="#" style="line-height:30px"><span>{{ratedType.type}}</span></a></div>
 <div ng-if="!isSelected"><a href="#" style="line-height:30px">{{ratedType.type}}</a><div>

and in your controller define-

$scope.isSelected = false;

Hope this helps :)

answered Feb 3, 2017 at 13:14

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.