Angular 2 ngFor Element Not Re Rendering With Two Way Data Binding -


i have table <tr> being loop ngfor. want show <tr> matches value of 2 way data binding property using <select>.

when app first load works fine when change select option view doesn't render desired.

__________code below__________

plunker code

html

<label>     hours     <select         [(ngmodel)]="location"         name="location">         <option *ngfor="let loc of locations" [value]="loc.id">{{loc.name}}</option>     </select> </label>  <table>     <thead>         <tr>           <th>location</th>             <th>day</th>             <th>open</th>             <th>close</th>         </tr>     </thead>     <tbody>         <tr *ngfor="let hour of hours">           <td *ngif="hour.locationid === location">                 locationid {{hour.locationid}}             </td>             <td *ngif="hour.locationid === location">                 {{hour.day}}             </td>             <td *ngif="hour.locationid === location">                 {{hour.daystart}}             </td>             <td *ngif="hour.locationid === location">                 {{hour.dayend}}             </td>         </tr>      </tbody> </table> 

component

hours: any[] = [     { locationid: 1, day: 'sunday', dayvalue: 0, daystart: '9:00am', dayend: '7:00pm', open: false, working: false },     { locationid: 1, day: 'monday', dayvalue: 1, daystart: '9:00am', dayend: '7:00pm', open: true, working: true },     { locationid: 1, day: 'tuesday', dayvalue: 2, daystart: '9:00am', dayend: '7:00pm', open: true, working: true },     { locationid: 1, day: 'wednesday', dayvalue: 3, daystart: '9:00am', dayend: '7:00pm', open: true, working: true },     { locationid: 1, day: 'thursday', dayvalue: 4, daystart: '9:00am', dayend: '7:00pm', open: true, working: true },     { locationid: 1, day: 'friday', dayvalue: 5, daystart: '9:00am', dayend: '7:00pm', open: true, working: true },     { locationid: 1, day: 'saturday', dayvalue: 6, daystart: '9:00am', dayend: '7:00pm', open: true, working: true },     { locationid: 2, day: 'sunday', dayvalue: 0, daystart: '9:00am', dayend: '8:00pm', open: false, working: false },     { locationid: 2, day: 'monday', dayvalue: 1, daystart: '9:00am', dayend: '8:00pm', open: true, working: true },     { locationid: 2, day: 'tuesday', dayvalue: 2, daystart: '9:00am', dayend: '8:00pm', open: true, working: true },     { locationid: 2, day: 'wednesday', dayvalue: 3, daystart: '9:00am', dayend: '8:00pm', open: true, working: true },     { locationid: 2, day: 'thursday', dayvalue: 4, daystart: '9:00am', dayend: '8:00pm', open: true, working: true },     { locationid: 2, day: 'friday', dayvalue: 5, daystart: '9:00am', dayend: '8:00pm', open: true, working: true },     { locationid: 2, day: 'saturday', dayvalue: 6, daystart: '9:00am', dayend: '8:00pm', open: true, working: true } ],  locations: any[] = [     { id: 1, name: 'location 1', },     { id: 2, name: 'location 2', } ];  location: number = 1; 

use ==instead of ===, or use [ngvalue] instead of [value].

with [value], values stored in location property string '1' or '2', , compare it, using ===, number 1 or 2. expression evaluated false.

working plunkr


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -