I'm beginner for the Angular and try to create Angular 5 ,when i click the radio button show and hide div area. ,I created customer-1
and customer-2
radio button when i click the customer-2 radio button is it not working (shown 1st div),That one is normal html to working fine, but it's not work for angular 5 , anyone know how to put that one correctly in Angular5?
Thanks
html
<div class="modal fade cust-my-modal cust-my-modal-2" id="signup_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">SIGN UP</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<div class="top-radio">
<div class="radio radio-primary">
<input type="radio" name="radio1" id="radio1" onClick="changediv('nc_signup')" checked="checked" value="option1">
<label for="radio1">
customers-1
</label>
</div>
<div class="radio radio-primary">
<input type="radio" name="radio1" id="radio2" onClick="changediv('cc_signup')" value="option2">
<label for="radio2">
customers-2
</label>
</div>
</div>
<form class="fotm" id="cc_signup" style="display: none;" action="rfq.html">
<div class="frm-btm-mrg">
<div class="form-group">
<input class="form-control" placeholder="Email id" type="text">
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" type="password">
</div>
<div class="form-group">
<input class="form-control" placeholder="Re-enter password" type="password">
</div>
<div class="form-group">
<input class="form-control" placeholder="Company name" type="text">
</div>
<div class="form-group">
<input class="form-control" placeholder="Website" type="text">
</div>
<div class="form-group">
<input class="form-control contact-num" placeholder="Contact number" type="text">
</div>
<div class="checkbox">
<input id="checkbox2" type="checkbox">
<label for="checkbox2">
I agree terms & conditions
</label>
</div>
</div>
<button type="submit" class="btn">Sign up</button>
</form>
<form class="fotm" id="nc_signup" action="rfq.html">
<div class="frm-btm-mrg-2">
<div class="form-group">
<input class="form-control" placeholder="User name" type="text">
</div>
<div class="form-group">
<input class="form-control" placeholder="Email id" type="text">
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" type="password">
</div>
<div class="form-group">
<input class="form-control" placeholder="Re-enter password" type="password">
</div>
<div class="checkbox">
<input id="checkbox3" type="checkbox">
<label for="checkbox3">
I agree terms & conditions
</label>
</div>
</div>
<button type="submit" class="btn">Sign ups</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
Live code- stackblitz
javascript
<script>
function changediv(divid){
$("#nc_signup").hide();
$("#cc_signup").hide();
$("#"+ divid).show();
}
</script>
function changediv(divid) { $("#nc_signup").hide(); $("#cc_signup").hide(); $("#"+ divid).show(); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <div class="modal fade cust-my-modal cust-my-modal-2" id="signup_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">SIGN UP</h4> </div> <div class="modal-body"> <div class="row"> <div class="col-sm-12"> <div class="top-radio"> <div class="radio radio-primary"> <input type="radio" name="radio1" id="radio1" onClick="changediv('nc_signup')" checked="checked" value="option1"> <label for="radio1"> customers-1 </label> </div> <div class="radio radio-primary"> <input type="radio" name="radio1" id="radio2" onClick="changediv('cc_signup')" value="option2"> <label for="radio2"> customers-2 </label> </div> </div> <form class="fotm" id="cc_signup" style="display: none;" action="rfq.html"> <div class="frm-btm-mrg"> <div class="form-group"> <input class="form-control" placeholder="Email id" type="text"> </div> <div class="form-group"> <input class="form-control" placeholder="Password" type="password"> </div> <div class="form-group"> <input class="form-control" placeholder="Re-enter password" type="password"> </div> <div class="form-group"> <input class="form-control" placeholder="Company name" type="text"> </div> <div class="form-group"> <input class="form-control" placeholder="Website" type="text"> </div> <div class="form-group"> <input class="form-control contact-num" placeholder="Contact number" type="text"> </div> <div class="checkbox"> <input id="checkbox2" type="checkbox"> <label for="checkbox2"> I agree terms & conditions </label> </div> </div> <button type="submit" class="btn">Sign up</button> </form> <form class="fotm" id="nc_signup" action="rfq.html"> <div class="frm-btm-mrg-2"> <div class="form-group"> <input class="form-control" placeholder="User name" type="text"> </div> <div class="form-group"> <input class="form-control" placeholder="Email id" type="text"> </div> <div class="form-group"> <input class="form-control" placeholder="Password" type="password"> </div> <div class="form-group"> <input class="form-control" placeholder="Re-enter password" type="password"> </div> <div class="checkbox"> <input id="checkbox3" type="checkbox"> <label for="checkbox3"> I agree terms & conditions </label> </div> </div> <button type="submit" class="btn">Sign ups</button> </form> </div> </div> </div> </div> </div> </div>
The Angular way to do this is to put code in app.component.ts instead of in a script-tag with jquery selectors.
You should have two member variables in your class that are changed by a method in the component.ts-fil, and bind to that method by using (click) in the HTML. To bind to variables in the code, use the [attr]-syntax.
You can take a look at my fork of your code here https://stackblitz.com/edit/angular-ktt3ri
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.