Topic: Label overlaps input on two way binding
Adrian Sawicki answered 7 years ago
I'm not sure how does your typescript part looks like so I will just give a working example.
In typescript:
myModel={name: 'test'};
In HTML:
<div class="md-form"> <input type="text" name="name" id="name" class="form-control" [(ngModel)]="myModel" mdbActive value={{myModel.name}} required > <label for="name"class="active">Name</label> </div>
With something in myModel.name the label goes up on page initialization.
Er Ka commented 7 years ago
Name [(ngModel)]="myModel" => Doing like this I think not a correct way? Also binding does not work for mdb-ng-select component.Adrian Sawicki answered 7 years ago
Er Ka commented 7 years ago
This is what I have in html: <div> <div><div class="md-form"></div> <div><input type="text"name="name"id="name"class="form-control"</div> <div>[(ngModel)]="item.name" #name="ngModel" required [value]="item.name" mdbActive></div> <div><label for="name"class="active">Name</label></div> <div><div class="alert alert-danger" *ngIf="f.submitted && name.invalid">Name is required</div></div> <div></div></div> <div></div> </div> My model is: item with name attributeAdrian Sawicki answered 7 years ago
stgiaf pro answered 7 years ago
Damian Gemza staff commented 7 years ago
Hello stgiaf, Please try to add class Active to your's label elements. This should fix your's problem. Please inform me how situation looks like. Best Regards, Damianstgiaf pro commented 7 years ago
Hi Damian, Thanks for your answer. I added class="active" to the label element., but it seems in the Inspection (Developer Tools in Chrome) that the class is removed somehow and the issue still persists. Please not that the page is opened via RouterLink. If I manually refresh the page, it works.Damian Gemza staff commented 7 years ago
Dear stgiaf, could you send me your's project without node_modules folder at d.gemza@mdbootstrap.com? I tried to reconstruct your's problem but for me everything is working fine. I created a second component, and filled it with form. In inputs i've putted data via ngModel. Made route from main component to second component via button. When second component is loaded, inputs are filled with data, and label goes up. https://screenshots.firefox.com/n0luPtBrub1Vqx7v/localhost Best Regards, Damianstgiaf pro commented 7 years ago
Hi, Sent via weTransferFREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- User: Free
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No