title: How to bind an input parameter of an Angular4 component
body: <p>I have a small web site I am developing in Angular4 (my first attempt in Angular) and have come across an issue I just can seem to figure out. Simplified down my scenario is:</p>
  
  <p>I have a component (account-list) which using a html5 select/option control which is populated from a rest api and displays a list of accounts.</p>
  
  <p>I have a second component which displays the details of the account (account-detail) and take accountId as an input parameter.</p>
  
  <p>When an account is selected in the account-list component I want the account-detail to auto update to the newly selected account. I know that my account-list component is working fine and that when I select an account the selectAccountId variable in the ts is being updated.</p>
  
  <p>However I just can't seem to get the update to the selectAccountId variable to trigger an update to the account-detail component. I know this component works fine on it own as a default account is displayed and the id of this default is set in the ngOnInit method of the account-list component.</p>
  
  <p>The relevant html5 in the account-list component:</p>
  
  <pre><code>&lt;select id="Id" #Id="ngModel" class="hideLabel form-control" [(ngModel)]="selectedAccountId" name="Id"&gt;
      &lt;option [ngValue]="account.Id" *ngFor="let account of accounts"&gt;  
          {{account.Name}}  
      &lt;/option&gt;  
  &lt;/select&gt;  
  
  &lt;!-- this div just to prove that selectedAccountId changes when a new account is selected, which it does --&gt;
  &lt;div *ngIf="selectedAccountId"&gt;
      {{selectedAccountId}}
  &lt;/div&gt;
  
  &lt;!-- this is the line which does not seem to work, changes to selectedAccountId are not triggering the component to refresh --&gt;
  &lt;account-detail *ngIf="selectedAccountId" [account]="selectedAccountId"&gt;&lt;/account-detail&gt;
  </code></pre>
  
  <p>The ts code of the account-list component:</p>
  
  <pre><code>export class AccountListComponent implements OnInit {
      selectedAccountId: number;
  
      title: string; 
      accounts: AccountHeader[];
      errorMessage: string;
  
      constructor(private accountService: AccountService, private router: Router) { }
  
      ngOnInit() {
          var s = this.accountService.getLatest();
  
          s.subscribe(
              accounts =&gt; {
              this.accounts = accounts; this.selectedAccountId = this.accounts[0].Id;
              },
              error =&gt; this.errorMessage = &lt;any&gt;error
          ); 
      }
  }
  </code></pre>
  
  <p>The ts code of the account-detail component:</p>
  
  <pre><code>export class AccountDetailComponent {
      @Input("account") selectedAccountId: number;
      account: Account;
  
      selectedLicense: License;
  
      constructor(
          private authService: AuthService, 
          private accountService: AccountService,
          private router: Router,
          private activatedRoute: ActivatedRoute) {
      }
  
      ngOnInit() {
          if (this.selectedAccountId) {
              this.accountService.get(this.selectedAccountId).subscribe(
                  account =&gt; this.account = account
              );
      }
  
          else {
              this.router.navigate([""]);
          }
      }
  } 
  </code></pre>
  
  <p>In all honesty I've lost track of the things I've tried to make this work, most of the blogs, guides etc I've read talk about how to bind the other way and I have all that working just fine. But I can't find how to get the binding to trigger an update of the account-detail component which should be accomplished by this line:</p>
  
  <pre><code>&lt;!-- this is the line which does not seem to work, changes to selectedAccountId are not triggering the component to refresh --&gt;
  &lt;account-detail *ngIf="selectedAccountId" [account]="selectedAccountId"&gt;&lt;/account-detail&gt;
  </code></pre>
  
  <p>I've been following a book in which this was working fine, but originally this was working in AngularJS and then migrated to Angular2 (then 4) and somewhere along the way this has stopped working.</p>
  
  <p>Any help would be much appreciated, thanks!</p>