angular - 角度过滤形式
问题描述
我尝试使用 Angular 实现按日期范围过滤的表单。按下按钮后没有任何反应。看起来没有选择路线。当我刚刚改变
[routerLink]="['/clients-rating/filtered',startDate,endDate" 到
[routerLink]="['/clients-rating/filtered','2019-03-01',2019-03-10" 我看到网址:http://localhost:9000/#/clients-rating/filtered/2019 -03-01/2019-03-10。
为什么输入的值没有从表单传输到组件?
我的代码:
客户评级.component.html
<html>
<body>
<div>
<input type="text" class="form-control" name="phone" id="start_date"
[(ngModel)]="startDate"/>
<input type="text" class="form-control" name="phone" id="end_date"
[(ngModel)]="endDate"/>
<button
[routerLink]="['/clients-rating/filtered',startDate,endDate"
class="btn btn-primary float-left
jh-create-entity create-clients-rating">
<fa-icon [icon]="'eye'"></fa-icon>
</button>
</div>
<body>
<html>
客户评级.route.ts
{
path: 'clients-rating/filtered/:startDate/:endDate',
component: ClientsRatingComponent,
data: {
authorities: ['ROLE_USER'],
},
canActivate: [UserRouteAccessService]
},
...
客户评级.component.ts
export class ClientsRatingComponent implements OnInit, OnDestroy {
clientsRatings: IClientsRating[];
startDate: String;
endDate: String;
constructor(
protected clientsRatingService: ClientsRatingService,
protected jhiAlertService: JhiAlertService,
protected eventManager: JhiEventManager,
protected accountService: AccountService,
protected activatedRoute: ActivatedRoute
) {
}
loadAll() {
this.clientsRatingService.query().subscribe(
(res: HttpResponse<IClientsRating[]>) => {
this.clientsRatings = res.body;
},
(res: HttpErrorResponse) => this.onError(res.message)
);
}
ngOnInit() {
this.startDate = this.activatedRoute.snapshot.paramMap.get('startDate');
this.endDate = this.activatedRoute.snapshot.paramMap.get('endDate');
if (this.startDate == null || this.endDate == null) {
this.loadAll();
} else {
this.clientsRatingService.filterByDate(this.startDate, this.endDate);
}
this.accountService.identity().then(account => {
this.currentAccount = account;
});
this.registerChangeInClientsRatings();
}
客户评级.service.ts
@Injectable({ providedIn: 'root' })
export class ClientsRatingService {
filterByDate(startDate: String, endDate: String,req?: any) {
const options = createRequestOption(req);
return this.http.get<IClientsRating[]>(`${this.resourceUrl}/filter /${startDate}/${endDate}`, {
params: options,
observe: 'response'
});
}
解决方案
我认为您错过]
了 RouterLink 的关闭。
但我会使用Router.navigate
按钮的(单击)事件:
TS 代码:
首先,导入路由器:
import { Router } from '@angular/router';
constructor(private router : Router) {}
navigateTo(){
this.router.navigate(['clients-rating/filtered/' + startDate + '/'+endDate+'']);
}
HTML 代码:
<html>
<body>
<div>
<input type="text" class="form-control" name="phone" id="start_date"
[(ngModel)]="startDate"/>
<input type="text" class="form-control" name="phone" id="end_date"
[(ngModel)]="endDate"/>
<button (click)="navigateTo()" class="btn btn-primary float-left jh-create-entity create-clients-rating">
<fa-icon [icon]="'eye'"></fa-icon>
</button>
</div>
<body>
<html>
推荐阅读
- python - AttributeError:模块 'pandas' 没有属性 'DataFrame'
- android - 当我在模拟器上运行应用程序时,Android Studio 文本不符合 layout_margin
- python - 对列表列表
- asp.net-mvc - ASP.NET Core Capturing POST data
- django - 如何制作具有复杂权限的 Django REST 用户 API
- javascript - 如何使用 html、css、bootstrap 在下拉列表中创建活动元素
- python - Tkinter 交互式和动态 GUI
- android - 当应用程序处于后台/被杀死时,Firebase FCM 不调用服务
- angular - rxjs6 - TypeError:无法读取未定义的属性“管道”
- javascript - React 组件不会重新渲染