gpt4 book ai didi

html - 模板应在同一个 div 中更改

转载 作者:太空宇宙 更新时间:2023-11-04 06:22:12 25 4
gpt4 key购买 nike

我正在做一个示例 Angular 元素。

所以我写了一个模板,一半应该是轮播,另一半应该是登录,如下所示:

login page

但是当我点击注册时,它占据了整个页面,但我希望它取代登录而不是页面的整个宽度。

signup

我希望该图片也应该在注册页面中可见。

app.component.html

<header>
<nav class="navbar navbar-lg navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" routerLink="/login">Brand</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" routerLink="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" (click)="logout()">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
</header>

<!-- main app container -->

<router-outlet></router-outlet>

登录component.html

<div class="row align-items-center">
<div class="col-6 col-sm-6 justify-content-center align-self-center align-items-center">
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="../assets/img7.jpg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="../assets/img8.jpg" alt=" Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="../assets/img10.jpg" alt=" Third slide">
</div>
</div>
</div>
</div>
<div class="col-5 col-sm-5 justify-content-center align-self-center align-items-center">
<div class="card">
<div class="card-body text-dark">
<h2>Login</h2>
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="username">Username</label>
<input type="text" formControlName="username" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.username.errors }" />
<div *ngIf="submitted && !!f.username.errors" class="invalid-feedback">
<div *ngIf="!!f.username.errors.required">Username is required</div>
</div>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" formControlName="password" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.password.errors }" />
<div *ngIf="submitted && !!f.password.errors" class="invalid-feedback">
<div *ngIf="!!f.password.errors.required">Password is required</div>
</div>
</div>
<div class="form-group">
<button [disabled]="loading" class="btn btn-primary mr-2">Login</button>

<img *ngIf="loading" src="data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA=="
/>
<a [routerLink]="['/signup']" class="btn btn-success">Sign Up</a>
</div>
</form>
</div>
</div>
</div>
</div>

注册.component.html

<div class="card">
<div class="card-body text-dark">
<h2>Sign Up</h2>
<form [formGroup]="signUpForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="firstName">First Name</label>
<input type="text" formControlName="firstName" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.firstName.errors }" />
<div *ngIf="submitted && f.firstName.errors" class="invalid-feedback">
<div *ngIf="f.firstName.errors.required">First Name is required</div>
</div>
</div>
<div class="form-group">
<label for="lastName">Last Name</label>
<input type="text" formControlName="lastName" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.lastName.errors }" />
<div *ngIf="submitted && f.lastName.errors" class="invalid-feedback">
<div *ngIf="f.lastName.errors.required">Last Name is required</div>
</div>
</div>
<div class="form-group">
<label for="flatNo">Flat No</label>
<input type="text" formControlName="flatNo" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.flatNo.errors }" />
<div *ngIf="submitted && f.flatNo.errors" class="invalid-feedback">
<div *ngIf="f.flatNo.errors.required">Last Name is required</div>
</div>
</div>
<div class="form-group">
<label for="gatedCommunity">Community Name</label>
<input type="text" formControlName="gatedCommunity" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.gatedCommunity.errors }" />
<div *ngIf="submitted && f.gatedCommunity.errors" class="invalid-feedback">
<div *ngIf="f.gatedCommunity.errors.required">Last Name is required</div>
</div>
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" formControlName="username" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.username.errors }" />
<div *ngIf="submitted && f.username.errors" class="invalid-feedback">
<div *ngIf="f.username.errors.required">Username is required</div>
</div>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" formControlName="password" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.password.errors }" />
<div *ngIf="submitted && f.password.errors" class="invalid-feedback">
<div *ngIf="f.password.errors.required">Password is required</div>
<div *ngIf="f.password.errors.minlength">Password must be at least 6 characters</div>
</div>
</div>
<div class="form-group">
<button [disabled]="loading" class="btn btn-primary">Register</button>
<img *ngIf="loading" src="data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA=="
/>
<a [routerLink]="['/login']" class="btn btn-link">Cancel</a>
</div>
</form>
</div>
</div>

提前致谢!

最佳答案

为此你需要在父组件中显示图像说 app.component.ts 我创建了一个 stackblitz 来让你理解。希望大家理解StackBlitz

<div class="col-md-4">
<img src="test.jpg">
</div>

<div class="col-md-8">
<router-outlet></router-outlet>
</div>

编辑

const appRoutes: Routes = [
{
path: '',
component: NormalSiteLayoutComponent, //layout with image
children: [
{ path: '', component: Login}
]
},
{
path: '',
component: AppLayoutComponent, //layout with header and no image
children: [
{ path: 'dashboard', component: DashboardComponent },
{ path: 'profile', component: ProfileComponent }
]
},

//no layout routes
{ path: 'home', component: HomeComponent},
{ path: 'test', component: TestComponent},
// otherwise redirect to home
{ path: '**', redirectTo: '' }
];

export const routing = RouterModule.forRoot(appRoutes);

关于html - 模板应在同一个 div 中更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55394586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com