html - Angular2: File input control label keeps its state after destroying component -
i have angular2 component (lets call dataset-create
) includes form:
<form novalidate="novalidate"> <button type="button" (click)="onclose()">close</button> <button type="submit" (click)="onsubmit()">submit</button> <label for="datafiled">data</label> <input id="datafiled" type="file" (change)="onfilechange($event)"> </form>
the close()
, submit()
functions emit (close)
event makes parent component disable dataset-create
component:
<div [ngswitch]="mode"> <template [ngswitchwhen]="'create'"> <dataset-create [dataset]="dataset" (close)="ondatasetformclose()"></dataset-create> </template> <template [ngswitchwhen]="'detail'"> <dataset-detail [dataset]="dataset" (close)="ondatasetformclose()"></dataset-detail> </template> </div>
this done bone binding emitted (close)
event of dataset-create
component following function in parent component:
private ondatasetformclose() { this.mode = "list"; }
so here first question: every time mode
variable toggles between 'create'
, else dataset-create
component created , destroyed. correct? correct! verified adding console.log("foo");
in constuctor on dataset-create
component.
here problem now: if above correct, why label of file input keeps it's value after submitting (thus destroying dataset-create
component) form?
to make things more clear here steps follow:
- i set somehow
mode
variable'create'
.dataset-create
component constructed. file input button has labelno file chosen
. - i click file input button , choose file (lets say,
foo.png
). file input label has labelfoo.png
. - i click submit button on form.
dataset-create
component destroyed. - i set somehow
mode
variable'create'
.dataset-create
component constructed. the file input button has labelfoo.png
. why? why label of file input control keeps previous state?
as suggested @astrone
this behavior until beta.0. angular2 used reuse created dom (see #4478, #5188, among others). workaround had use app_view_pool_capacity
tell angular2 not cache dom.
since beta.1 no longer issue, , using app_view_pool_capacity
no longer necessary. part of #5993 every dom node recreated propertly (see @tbosch's comment).
Comments
Post a Comment