0
votes

I am trying to use "Inputs with background animated border - Material 2.0" inputs as seen here: https://mdbootstrap.com/docs/jquery/forms/inputs/#animated-inputs

I am also using the "Lazy Loading" approach (with regards to routing).

This is the original

enter image description here

This is how it should work

enter image description here

This is what it ~actually~ does

enter image description here

The problem is the "Input field" does not work properly. When entering the data, the characters "write over" the label

How can this be fixed? If this requires a specific module, where can one find information on the necessary modules needed with each component? Or - does one have to import ~all~ MDB Modules (or Material modules) when creating "separate components" (usingng generate component) in the module.ts file for the "separate component"?

ETA:

I have seen this message here: Angular Material Date-Picker is not working properly

  1. I have added Angular Material to the project (see package.json below)

  2. I have tried to add BrowserAnimationsModule as follows in authorizatin.module.ts as follows:

    import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { AuthorizationRoutingModule } from './authorization-routing. module';

    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

    [... snip ...]

    @NgModule({ declarations: [ authRoutingComponents ], exports: [ authRoutingComponents, AuthorizationRoutingModule ], imports: [ BrowserAnimationsModule, CommonModule, ButtonsModule, AuthorizationRoutingModule,

but got the following error

Uncaught (in promise): Error: BrowserModule has already been loaded.

Again, any info on the issue is appreciated.

Error I am getting when adding BrowserAnimationsModule

enter image description here

File: package.json

{
  "name": "trading",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.14",
    "@angular/cdk": "~8.2.3",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@fortawesome/fontawesome-free": "^5.12.0",
    "@types/chart.js": "^2.9.12",
    "animate.css": "^3.7.2",
    "chart.js": "^2.5.0",
    "easy-pie-chart": "^2.1.7",
    "hammerjs": "^2.0.8",
    "ng-uikit-pro-standard": "git+https://oauth2:<api_key>[email protected]/mdb/angular/ng-uikit-pro-standard.git",
    "rxjs": "~6.4.0",
    "screenfull": "^3.3.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.23",
    "@angular/cli": "~8.3.23",
    "@angular/compiler-cli": "~8.2.14",
    "@angular/language-service": "~8.2.14",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}

File: login.component.html

<div>   <!--Form with header-->   <div class="card">
    <div class="card-block">

      <!--Header-->
      <div class="form-header  purple darken-4">
        <h3><i class="fa fa-lock"></i> Login:</h3>
      </div>

      <!--Body-->
      <div class="md-form">
        <i class="fa fa-envelope prefix"></i>
        <input type="text" id="form2" class="form-control">
        <label for="form2">Your email</label>
      </div>

      <div class="md-form">
        <i class="fa fa-lock prefix"></i>
        <input type="password" id="form4" class="form-control">
        <label for="form4">Your password</label>
      </div>

      <div class="text-center">
        <button class="btn btn-deep-purple">Login</button>
      </div>

    </div>

    <!--Footer-->
    <div class="modal-footer">
      <div class="options">
        <p>Not a member? <a href="#">Sign Up</a></p>
        <p>Forgot <a href="#">Password?</a></p>
      </div>
    </div>

  </div>   <!--/Form with header--> </div>

File: login.component.ts

import { Component, OnInit } from '@angular/core';
// MDB Angular Pro

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

File: authorization-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

// components that we need to navigate to
import { LoginComponent } from './login/login.component';
import { ForgotPasswordComponent } from './forgot-password/forgot-password.component';
import { RegisterComponent } from './register/register.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';

export const routesAuth : Routes = [
    { path: 'login' , component: LoginComponent },
    { path: 'register' , component: RegisterComponent },
    { path: 'forgot-pass' , component: ForgotPasswordComponent },
    { path: '**' , component: PageNotFoundComponent }
];

@NgModule({
    imports: [ RouterModule.forChild(routesAuth)], 
    exports: [ RouterModule ],
    declarations: [   ]
  })

export class AuthorizationRoutingModule {}

export const authRoutingComponents = [ LoginComponent, RegisterComponent, ForgotPasswordComponent, PageNotFoundComponent ]

File: authorization.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AuthorizationRoutingModule } from './authorization-routing. module';


import { authRoutingComponents  } from './authorization-routing. module';

// items that go with the Component
import { AccordionModule } from 'ng-uikit-pro-standard';
import { CardsModule } from 'ng-uikit-pro-standard';
import { CheckboxModule } from 'ng-uikit-pro-standard';
import { IconsModule } from 'ng-uikit-pro-standard';
import { ButtonsModule } from 'ng-uikit-pro-standard';

@NgModule({
  declarations: 
            [ authRoutingComponents  ],
  exports:  [  authRoutingComponents, 
              AuthorizationRoutingModule 
            ],
  imports:  [ CommonModule, 
              ButtonsModule,
              AuthorizationRoutingModule,     
              AccordionModule, 
              CardsModule,
              CheckboxModule,
              IconsModule
            ]
})

export class AuthorizationModule { }
1

1 Answers

2
votes

The code you provided is from MDB jQuery version. Here is the documentation for Angular version: https://mdbootstrap.com/docs/angular/forms/inputs/

You need to add 'mdbInput' directive to the input element and include InputsModule.forRoot() in your module imports.