Omkar Dixit Omkar Dixit - 1 year ago 78
CSS Question

disable a button if json is empty

i need disable a button using css or angular, but it has to be according to the json, i mean if book.BookGanga is empty then the button has to be disabled, if book.BookGanga is not empty then the button has to be shown.

<div class="modal fade" id="example{{$index}}" role="dialog">
<div class="modal-dialog modal-lg">
<!--the modal content-->
<div class="modal-content">
<div class="modal-header">
<button class="btn btn-danger" style="float:right" type="button" data-dismiss="modal">&times;</button>
<h2 class="modal-title text-center">{{book.Name}}</h2>
<h5 class="text-center">{{book.Type}}</h5>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-2">
<img ng-src="{{book.ImageUrl}}" class="img-responsive" " />
</div>
<div class="col-md-10 ">
{{book.Description}}
<hr />
<h5>Pages: {{book.pages}}</h5>
<h5>Price: {{book.Rate}}</h5>
<h5>Language: Marathi</h5>
<h5>Binding: Paperback</h5>
<h5> Authors: Sri Dr. Narayananandanatha katesvamiji </h5>
</div>
</div>
</div>
<div class="modal-footer ">
<div class="fb-share-button " data-href="{{book.BookGanga}} " data-layout="button_count " data-size="large " data-mobile-iframe="true "><a class="fb-xfbml-parse-ignore " target="_blank " href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&amp;src=sdkpreparse ">Share</a></div>
<a class="btn btn-success " style="margin-top:-.2em; " href="{{book.BookGanga}} "><span class="glyphicon glyphicon-shopping-cart "></span>&nbsp; Buy Online</a>
</div>
</div>
</div>
</div>

Answer Source

I think you are using Bootstrap so You can try this as well:

<button ng-class = "{disabled : book.BookGanga.length == 0}">

Find out the learning material for the ng-Class

I hope It will work for you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download