I'm creating a component that changes an index based on the value selected from a dropdown. The dropdown itself is a stylised one rather than a native element and so updates a hidden input field. That field is in the template and has a binding with the variable in the component.
Here is the component and template:
import { Component, ElementRef, Input, OnInit } from '@angular/core';
import { Spell } from '../../models/spell';
/**
 * This class represents a Spell component
 */
@Component({
  moduleId: module.id,
  selector: 'ui-spell',
  templateUrl: 'spell.component.html',
  styleUrls: ['spell.component.css']
})
export class SpellComponent implements OnInit {
  @Input() spell: Spell;
  level: number;
  constructor(private el: ElementRef) {
    this.level = 1;
  }
  ngOnInit() {
  }
  update() {
    console.log(this.level);
  }
}
<div class="ui dropdown button">
  <input name="level" type="hidden" [(ngModel)]="level">
  <div class="text">Rank 1</div>
  <i class="dropdown icon"></i>
  <div class="menu">
    <div class="item" data-value="1">Rank 1</div>
    <div class="item" data-value="2">Rank 2</div>
    <div class="item" data-value="3">Rank 3</div>
    <div class="item" data-value="4">Rank 4</div>
    <div class="item" data-value="5">Rank 5</div>
  </div>
</div>
<button (click)="update()">Update</button>
The value of the input successfully changes but if I click on the Update button, the level still outputs as '1'. If I change the starting value in the component and inspect the input, the value has changed to match. There's no errors anywhere to explain why the value is not returned to the component. I have no idea where to look next.


ngModelto take up the change, you need to ensure thechangeevent is fired from the<input type="hidden">forngModelto take up the change.@Input()is redundant here because it's only relevant when you pass data toSpellComponentfrom the outside - like<ui-spell [spell]="1">