I have a angular component which has a form with two pulldowns. The first pulldown is a pretty simple. The user can select from a static list of items. The second pulldown is a select2 which should allow the user to selected from a list of results that are pulled from a remote API. I need to be able to change the url the select2 component uses when the user changes their selection in the first pulldown.
Here is the code I have now:
HTML:
   <div class="row">
      <div class="col-md-3">
        <div style="margin-top:10px;text-align: right;font-weight: bold">
          <label> Node </label>
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group half-margin-bottom">
          <div class="form-group__text ">
            <select name="node" id="node" (ngModelChange)="filtersNodeChange($event)" [(ngModel)]="userInputNode">
              <option *ngFor="let node of nodePullDownValues" [value]="node">{{ node }}</option>
            </select>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <div class="row">
      <div class="col-md-3">
        <div style="margin-top:10px;text-align: right;font-weight: bold">
          <label> Filter Key </label>
        </div>
      </div>
      <div class="col-md-6">
        <div class="form-group half-margin-bottom">
          <div class="form-group__text ">
            <select2 [options]="select2Options"></select2>
          </div>
        </div>
      </div>
    </div>
  </div>
TypeScript:
export class MappingDynamicComponent implements OnInit {
   ... omitted for brevity ...
   userInputNode = 'unknown';
   ... omitted for brevity ...
   constructor( ... ) {
      ...
   }
   setSelect2Options () {
     this.select2Options = {
       'width': '100%',
       'minimumInputLength': 3,
       'ajax': {
         'url': "http://dev-03.example.com:5200/api/v1/cm/cm_list/?cm_type=" + this.userInputNode + "&start_date=" + this.startDate,
        'dataType': 'json',
        'data': function (params) {
           var query = { 'starts_with': params.term, 'page': params.page || 1 };
           // Query parameters will be ?search=[term]&page=[page]
           return query;
        },
        'processResults': function (data) {
           var results = [];
           for (var i = 0; i < data.results.length; i++ ) { results.push( { "id": i+1, "text": data.results[i]} ); }
           // Tranforms the top-level key of the response object from 'items' to 'results'
           return { 'results': results };
        }
      }
    };
  }
  ... omitted for brevity ...
  filtersNodeChange(event) {
    this.userInputNode = event;
    this.setSelect2Options();
  }
  ngOnInit() {
    this.errorText = "";
    this.setStartDate();
    this.setNodePullDownValues();
    this.activatedRoute.queryParams.subscribe(params => {
      this.userInputNode = params['node'];
      this.setSelect2Options();
      ... omitted for brevity ...
    });
  }
The problem I am having is the url being used by the select2 component does not change when the user selects new option from the first pulldown.
I had hoped that the filtersNodeChange() would change the value of the query parameter cm_list to what user has selected from the first pulldown.