Skip to content

Async elements that act as a form without a submit button

Okay, so this may seem like a lot to ask. I have been pounding my head against the desk trying to figure this out. Take the below example:

   <li>Number: <span id="Number">123</span></li>

I am wanting to create basically an asyncronous link between the span with the id of “Number”, and the database. Is it possible to give the user the ability to click the element, then the input can be changed, and then the updated value be sent to the database on either Enter/Return or unfocus? This is just a small personal project, I am wanting to add a little bit of uniqueness to this. So any help would be fantastic!


So now I have it almost where it needs to be. However the apiCall() function will not call using the interpolation method of showing data. Any ideas on how to get around this? Below is the code and the error:

<table class="table table-striped">
                <th scope="col">Expense</th>
                <th scope="col">Amount</th>
              <ng-container *ngFor="let exp of expenses">
                    <th scope="row"><input type="text" class="formless" name="{{exp.expense}}" placeholder="{{exp.expense}}" (focusout)="apiCall({{}}, {{exp.expense}})"></th>
                    <td><input type="text" class="formless" placeholder="{{exp.price}}"></td>


error NG5002: Parser Error: Unexpected
token {, expected identifier, keyword, or
string at column 10 in [apiCall({{}},
{{exp.expense}})] in


You might want to try with <input/> instead of span, so that it is always editable. For saving on update, you could bring in some function on (focusout) in html.

<input [(ngModel)]="variableForStoringData" (focusout)="saveApiCall()" />