将 html ngModel 值传递给服务 --Angular
我想传递一个 html ngModel 值
在服务内部,我有以下代码:
selectedYear=2022;
configUrl1 = 'https://localhost:44361/api/Active_Serviced_Outlets?Year='+this.selectedYear+'&quarter=1&month=1';
getMethod1() {
return this.http.get(this.configUrl1);
}
我想动态地将 [(ngModel)]="selectedYear" 值传递给选定的年份,以便每次用户输入年份时。
ComboComponent.html
我想传递一个 html ngModel 值
在服务内部,我有以下代码:
configUrl1 = 'https://localhost:44361/api/Active_Serviced_Outlets?Year=2021&quarter=1&month=1';
getMethod1() {
return this.http.get(this.configUrl1);
}
我想动态地将 [(ngModel)]="selectedYear" 值传递给选定的年份,以便每次用户输入年份时。
ComboComponent.html
<div class="row">
<div class="column">
<p> <b>Year </b></p>
<kendo-dropdownlist [data]="year" [(ngModel)]="selectedYear"></kendo-dropdownlist>
</div>
</div>
ComboComponent.ts
public year: Array<string> = [
"2022",
"2021",
"2020",
"2019",
"2018",
];
public get selectedYear() {
return this._homeServise.selectedYear;
}
public set selectedYear(year: number) {
this._homeServise.selectedYear = year;
}
I want to pass an html ngModel value <kendo-dropdownlist style=" width: 92%;" [data]="year" [(ngModel)]="selectedYear"> which is located on Combocomponent.html, to a service which is called Home.service.ts.
Inside the service I have this code:
selectedYear=2022;
configUrl1 = 'https://localhost:44361/api/Active_Serviced_Outlets?Year='+this.selectedYear+'&quarter=1&month=1';
getMethod1() {
return this.http.get(this.configUrl1);
}
I want to dynamically pass the [(ngModel)]="selectedYear" value to selected Year so every time the user inputs an year.
ComboComponent.html
I want to pass an html ngModel value <kendo-dropdownlist style=" width: 92%;" [data]="year" [(ngModel)]="selectedYear"> which is located on Combocomponent.html, to a service which is called Home.service.ts.
Inside the service I have this code:
configUrl1 = 'https://localhost:44361/api/Active_Serviced_Outlets?Year=2021&quarter=1&month=1';
getMethod1() {
return this.http.get(this.configUrl1);
}
I want to dynamically pass the [(ngModel)]="selectedYear" value to selected Year so every time the user inputs an year.
ComboComponent.html
<div class="row">
<div class="column">
<p> <b>Year </b></p>
<kendo-dropdownlist [data]="year" [(ngModel)]="selectedYear"></kendo-dropdownlist>
</div>
</div>
ComboComponent.ts
public year: Array<string> = [
"2022",
"2021",
"2020",
"2019",
"2018",
];
public get selectedYear() {
return this._homeServise.selectedYear;
}
public set selectedYear(year: number) {
this._homeServise.selectedYear = year;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每当值更新时,您都需要将值传递给服务。
在模板中,
在 ts 中,
You need pass the value to service whenever the value is updated.
In template,
In ts,