Tips for Incorporating Material Design Lite into Angular2

I have encountered a minor issue while trying to incorporate material design into Angular2. I am using the latest version of Angular2, but the MDL framework seems to be incompatible.

Here is what I have done so far:

npm install material-design-lite --save

<link rel="stylesheet" href="/node_modules/material-design-lite/material.min.css">
<link rel="stylesheet" href="/app/themes/material.deep_purple-purple.min.css">
<script src="/node_modules/material-design-lite/material.min.js"></script>

In the MaterialDesignLiteUpgradeElement.ts file :

import {Directive, AfterViewInit} from '@angular/core';
declare var componentHandler: any;
@Directive({
    selector: '[mdl]'
})    
export class MdlUpgradeDirective implements AfterViewInit {
    ngAfterViewInit() {
    if (componentHandler) {
        componentHandler.upgradeAllRegistered();
    }
 }
}

And in the app.component.ts file :

import { Component, NgModule} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MdlUpgradeDirective } from '../app/directives/MaterialDesignLiteUpgradeElement';
@NgModule({
  imports:      [ BrowserModule ],
  declarations: [ MdlUpgradeDirective ],
  bootstrap:    [ AppComponent ]
})
@Component ({
  selector: 'my-app',
  templateUrl: '../app/app.component.html'
})
    export class AppComponent {
     }

package.json:

"dependencies": {
    "@angular/common": "~2.1.1",
    "@angular/compiler": "~2.1.1",
    "@angular/core": "~2.1.1",
    "@angular/forms": "~2.1.1",
    "@angular/http": "~2.1.1",
    "@angular/platform-browser": "~2.1.1",
    "@angular/platform-browser-dynamic": "~2.1.1",
    "@angular/router": "~3.1.1",
    "@angular/upgrade": "~2.1.1",
    "angular-in-memory-web-api": "~0.1.13",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.39",
    "zone.js": "^0.6.25"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.34",
    "@types/node": "^6.0.45",
    "concurrently": "^3.0.0",
    "lite-server": "^2.2.2",
    "typescript": "^2.0.3"
  }

material-design-lite -version v1.2.1

Answer №1

To integrate Material Design Lite into your Angular project using Angular CLI, you can add the following code snippet to your angular-cli.json file:

   "styles": [
      "../node_modules/material-design-lite/material.css",
      "../node_modules/material-design-icons/iconfont/material-icons.css"
  ],
  "scripts": [
      "../node_modules/material-design-lite/material.min.js"
  ],

Check out the code here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can Angular ping local addresses in a manner similar to using the terminal?

Looking for a way to ping devices on my local network, similar to using the ping command in the terminal to ping the router or any connected devices. I've figured out how to ping servers like google.com, but it doesn't seem to work with local add ...

Splitting a string in Typescript based on regex group that identifies digits from the end

Looking to separate a string in a specific format - text = "a bunch of words 22 minutes ago some additional text". Only interested in the portion before the digits, like "a bunch of words". The string may contain 'minute', & ...

Using a Typescript variable prior to its assignment

I encountered an issue in my Typescript / ReactJS project displaying the error message Variable 'myVar' is used before being assigned. TS2454 This problem arises with my TS version 4.2.3, appearing both in my IDE and during code execution. Inte ...

Choose the property category

Is there a more efficient way to specify the type of a property in TypeScript without resorting to casting? Take a look at this example: interface Overlay { type: "modal" | "drawer" other?: number } const rec = { obj1: { ty ...

How to disable click event binding in Angular2 after it has been clicked once

Within my application, there is a button that has a click event attached to it: <button class="btn btn-default" (click)="doSomething()"> I am wondering if there is a way to remove the (click) event from the button within the doSomething method so t ...

Building an AngularJS Service with TypeScript that is Non-Singleton: A Step-by-Step Guide

I need help converting an AngularJS Typescript Service into a Non-Singleton. Can anyone provide guidance on how to achieve this? (Note: This is not the same as other questions that focus on achieving this in JS) I have included some simple pseudo code be ...

Unleashing the Potential: Integrating a Scanner Device with

Currently, I'm facing the challenge of integrating a Scanner device with my Angular application. On one of the pages dedicated to scanning, users are able to view an alert indicating the connection status of the Scanner as well as any scanned document ...

Angular ngx-translate Feature Module failing to inherit translations from Parent Module

Currently, I am implementing lazy loading for a feature module. I have imported TranslateModule.forChild() with extend true to load feature-specific translations. In my app.module, I am importing TranslateModule.forRoot to load common translations. The i ...

Unending loop caused by nested subscriptions - Angular / RxJS

I am currently implementing a nested subscribe operation, although I am aware that it may not be the most efficient method. Here is an example of what I have: this.route.params.subscribe((params) => { this.order$ .getMa ...

Send a function as a property to a child functional component

I am attempting to pass a callback function to a functional component child in order to update the parent. However, I am encountering an error Uncaught TypeError: updateVal is not a function within the child component (I will add a comment to indicate wh ...

Angular is unable to locate the control without a specified name attribute

This question seems to crop up several times every year, but I'm struggling to make it work. I need to dynamically create a formArray based on elements provided by an array. I've tried various approaches and I'm currently stuck. One of the s ...

How can I use Laravel to enter data using the post method?

I've been struggling with data transfer in my Angular component for a while now, specifically using a post method. Despite extensive research and reading various documents, I haven't been able to find a solution. Can you assist me with this issue ...

Create a typescript class object

My journey with Typescript is just beginning as I delve into using it alongside Ionic. Coming from a background in Java, I'm finding the syntax and approach quite different and challenging. One area that's giving me trouble is creating new object ...

Showing nested routes component information - Angular

I am working on a project that includes the following components: TodosComponent (path: './todos/'): displaying <p>TODO WORKS</p> AddTodosComponent (path: './todos/add'): showing <p>ADD TODO WORKS</p> DeleteTo ...

Angular does not display a loading indicator in the header

When handling service calls, I have implemented a loading indicator to provide feedback to the user. However, it appears that this indicator is not effectively preventing users from interacting with header items before the loading process is complete. My ...

What steps do I need to take in order to set up InfluxDB with Nest

As a beginner in the world of software development, I am eager to expand my knowledge and skills. Has anyone had experience operating influxdb with nestjs? If so, I would greatly appreciate it if you could share your past experiences. Thank you for takin ...

What are the steps to fix errors when deploying a MEAN stack application on Heroku?

Upon building my Angular app with a Node.js API and deploying it on Heroku, I encountered an error. Despite this, the app runs smoothly with no errors when tested on my local server. Below are the logs from Heroku: C:\Users\PC>heroku logs -a= ...

Sharing information between sibling components in Angular

https://i.sstatic.net/Pn74N.png The image above showcases my Angular 2 application, where the Main component is divided into two child components: "FromComponent" and "ToComponent". The "FromComponent" displays a list of items with a checkbox beside each ...

Is it feasible to access and modify local files within an Angular project using TypeScript code in the angular component.ts file? If so, how can this be achieved?

My Angular application is built on version 4 or higher. I have a setup in my project where there is a folder containing a txt file and another folder next to it with an angular component.ts file: FolderWithFile -----file.txt ComponentFolder -----person.co ...

Issue with running "ng generate" or "ng add" commands

While using angular version 8 in Termux Android ARM, I encountered an issue when trying to add the PWA and service worker to my website project. Here is the information about the angular version obtained from Angular CLI: $ ng version _ ...