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> &nbsp; &nbsp;<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;
  }

推荐答案

You need pass the value to service whenever the value is updated.

In template,

<kendo-dropdownlist (ngModelChange)="onChange($event)"  [data]="year" [(ngModel)]="selectedYear"></kendo-dropdownlist>

In ts,

onChange(year){
 this._homeServise.selectedYear = this.selectedYear;
}

Angular相关问答推荐

not getting circular input switch primeng组件

tabindex on button on button in MatMenu in angular不工作

如何在Angular中执行一个操作条件为多个可观测值?

以Angular 将指令事件从子组件传递到父组件

如何在init为FALSE时以Angular 初始化主拇指擦除器-Swiper 11.0.6Angular 17 SSR

Angular :为什么我得到了一个可观察到的共鸣

Angular 17多内容投影错误

HTTP拦截器在Angular 17项目中不起作用

对Angular 为17的路径使用AuthGuard

NGX-Translate如何不得到404?

大型 Angular 12 应用程序 - 我如何管理 js 文件

组件的导入不能以Angular 工作

Angular 无法从后端获取数据到前端

Angular SPA 和 .Net 6 API 之间未连接 Application Insights Map

当我ng serve时,Angular CLI 提示TypeError: callbacks[i] is not a function

异步管道模板中的局部变量(Angular 2+)

在 Angular material表上调用 renderRows()

Angular 2: Debounce(ngModelChange)?

找不到模块'@angular/compiler'

如何添加/设置环境 Angular 6 angular.json 文件