vendredi 6 octobre 2017

Angular 4 - checkbox becomes unchecked on data update

So I have the following html in my app.component.html:

<div class="links-panel">
    <h1>URL Validation</h1>
    <div class="link" *ngFor="let property of link_keys; let i = index">
        <label class="label">Email Url:</label>
        <input type="input" disabled="true" value="" class="email-url">
        <p class="https-checkbox-row"><i class="fa fa-question-circle" aria-hidden="true"></i> Change to Https <input type="checkbox" id="https-checkbox-" (click)="resolveHttps(property, i)"></p>
        <div class="link-details" *ngFor="let link of links[property]; let j = index;">
            .
            .
            .
        </div>
        .
        .
        .
    </div>
</div>

I have the following code in my app.component.ts that is triggered when a checkbox is checked that changes a link's name (which is an object key) to a newer one prefixed with https://.

//link.url contains the new url prefixed with https://
this.links[link.url] = this.links[property];
this.link_keys[this.link_keys.indexOf(property)] = link.url;
delete this.links[property];

This all works fine and good, however when the view gets updated with the new data changes, the "Change to Https" checkbox becomes unchecked.

Is there any way to have a callback when the data changes, so that I can recheck the checkbox, or is there a way to make sure that the checkbox remains checked after the view updates?




Aucun commentaire:

Enregistrer un commentaire