angular - How can I do dynamic layouts templates with Bootstrap grid? -
i working boostrap , angular 4. create register component , want reuse html in other place. html code
<div class="col-md-4 col-sm-6 col-md-offset-4 col-sm-offset-3"> <div class="card"> <div class="card-header text-center" data-background-color="purple"> <br> <h4 class="title">registrate</h4> <br> </div> <p class="category text-center">unete nosotros</p> <div class="card-content"> <div class="input-group"> <span class="input-group-addon"> <i class="material-icons">face</i> </span> <div class="form-group label-floating"> <label class="control-label">nombre</label> <input type="text" class="form-control"> <span class="material-input"></span> </div> </div> <div class="input-group"> <span class="input-group-addon"> <i class="material-icons">email</i> </span> <div class="form-group label-floating"> <label class="control-label">correo</label> <input type="email" class="form-control"> <span class="material-input"></span> </div> </div> <div class="input-group"> <span class="input-group-addon"> <i class="material-icons">lock_outline</i> </span> <div class="form-group label-floating"> <label class="control-label">contraseƱa</label> <input type="password" class="form-control"> <span class="material-input"></span> </div> </div> <div class="footer text-center"> <button type="submit" class="btn btn-rose btn-simple btn-wd btn-lg"> ok <div class="ripple-container"></div> </button> </div> </div> </div> </div>
in other view want set class property col-md-4 col-sm-6 col-md-offset-4 col-sm-offset-3. can more dynamic?
use ngclass property of angular 2 below set dynamic class:
<some-element [ngclass]="{'first': true, 'second': true, 'third': false}">...</some-element>
modify template like
register component template ...
in register component selector eg. register-comp
@input() public page: string; getclassbypagetype(): string { if(this.page === 'page1'){ return 'col-md-4 col-sm-6 col-md-offset-4 col-sm-offset-3'; } else if(this.page === 'page2') { return 'col-md-2 col-sm-5 col-md-offset-6 col-sm-offset-4'; } return 'col-md-4 col-sm-6 col-md-offset-4 col-sm-offset-3'; // default }
in other component template send page register component below
<div class='page1-comp'> <register-comp page='page1'></register-comp> </div> <div class='page2-comp'> <register-comp page='page2'></register-comp> </div>
Comments
Post a Comment