0

I'm trying to get angular-mdc-web to work with the vs2017 .net core angular template. So far without luck.

  • the ripple effect of the buttons are strange
  • while clicking the button, the button gets completely white
  • when sizing chrome, the click dimension doesn't move with it

Please have a look at the Demo-Gif: Demo Gif

EDIT 12.04.2018

All works now, thanks to trimox! You can clone/download the solution from vs2017-Angluar-Template-with-mdc-web

According to the following Get started Tutorial: Angular MDC - Getting started

I know, the following steps destroys the bootstrap stuff. But I just want the button to work.

Question is: How do I get angular-mdc-web work with the vs2017 Angular-Template? Thanks for your help!

Here how i did my setup: VS2017 Community Edition 15.6.4

  1. Menu File\New\Project...
  2. ASP.NET Core Web Application
  3. Select Angular

  4. Edit package.json (ready for angular5 with vs2017, no bootstrap)

{
  "name": "WebApplication2",
  "private": true,
  "version": "0.0.1",
  "scripts": {
    "test": "karma start ClientApp/test/karma.conf.js",
    "build:vd": "webpack --config webpack.config.vendor.js",
    "build:cl": "webpack --config webpack.config.js",
    "build:dev": "webpack --progress --color",
    "build:aot": "webpack --env.aot --env.client & webpack --env.aot --env.server"
  },
  "dependencies": {
    "@angular/animations": "^5.2.9",
    "@angular/common": "^5.2.9",
    "@angular/compiler": "^5.2.9",
    "@angular/compiler-cli": "^5.2.9",
    "@angular/core": "^5.2.9",
    "@angular/forms": "^5.2.9",
    "@angular/http": "^5.2.9",
    "@angular/platform-browser": "^5.2.9",
    "@angular/platform-browser-dynamic": "^5.2.9",
    "@angular/platform-server": "^5.2.9",
    "@angular/router": "^5.2.9",
    "@angular-mdc/web": "^0.34.1",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.12",
    "isomorphic-fetch": "2.2.1",
    "jquery": "^3.3.1",
    "preboot": "6.0.0-beta.3",
    "reflect-metadata": "0.1.12",
    "rxjs": "^5.5.8",
    "zone.js": "^0.8.21"
  },
  "devDependencies": {
    "@ngtools/webpack": "^1.10.2",
    "@types/chai": "^4.1.2",
    "@types/jasmine": "^2.8.6",
    "@types/webpack-env": "~1.13.5",
    "angular2-router-loader": "0.3.5",
    "angular2-template-loader": "0.6.2",
    "aspnet-prerendering": "^3.0.1",
    "aspnet-webpack": "^2.0.3",
    "awesome-typescript-loader": "4.0.1",
    "chai": "^4.1.2",
    "clean-webpack-plugin": "^0.1.19",
    "css": "^2.2.1",
    "css-loader": "0.28.11",
    "expose-loader": "0.7.5",
    "extract-loader": "^2.0.1",
    "extract-text-webpack-plugin": "3.0.2",
    "file-loader": "1.1.11",
    "html-loader": "0.5.5",
    "jasmine-core": "^3.1.0",
    "json-loader": "0.5.7",
    "karma": "^2.0.0",
    "karma-chai": "^0.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.1.1",
    "karma-webpack": "^2.0.9",
    "loader-utils": "^1.1.0",
    "node-sass": "^4.8.3",
    "raw-loader": "0.5.1",
    "sass-loader": "^6.0.7",
    "style-loader": "0.20.3",
    "to-string-loader": "1.1.5",
    "typescript": "2.7.2",
    "url-loader": "1.0.1",
    "webpack": "^3.10.0",
    "webpack-hot-middleware": "^2.21.2",
    "webpack-merge": "^4.1.2"
  }
}
  1. Edit webpack.config.vendor.js
...
const nonTreeShakableModules = [
    '@angular-mdc/web',                         // add this line
//    'bootstrap',                              // remove this line
//    'bootstrap/dist/css/bootstrap.css',       // remove this line
    'es6-promise',
    'es6-shim',
    'event-source-polyfill',
    'jquery',
];
...

and

...
const sharedConfig = {
    stats: { modules: false },
    resolve: { extensions: ['.js'] },
    module: {
        rules: [
            { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, use: 'url-loader?limit=100000' }
        ]
    },
    output: {
        publicPath: 'dist/',
        filename: '[name].js',
        library: '[name]_[hash]'
    },
    plugins: [
        new CleanWebpackPlugin([path.join(__dirname, 'ClientApp', 'dist'), path.join(__dirname, 'wwwroot', 'dist')]), // add this line
        new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
        new webpack.ContextReplacementPlugin(/\@angular\b.*\b(bundles|linker)/, path.join(__dirname, './ClientApp')), // Workaround for https://github.com/angular/angular/issues/11580
        // new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)@angular/, path.join(__dirname, './ClientApp')), // deactivate this line
        new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)esm5/, path.join(__dirname, './ClientApp')), // add this line
        new webpack.IgnorePlugin(/^vertx$/) // Workaround for https://github.com/stefanpenner/es6-promise/issues/100
    ]
};
...
  1. Edit webpack.config.js
...
const merge = require('webpack-merge');
// const AotPlugin = require('@ngtools/webpack').AotPlugin; // remove this line
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin; // add this line
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
...

and

...
    const sharedConfig = {
        stats: { modules: false },
        context: __dirname,
        resolve: { extensions: [ '.js', '.ts' ] },
        output: {
            filename: '[name].js',
            publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
        },
        module: {
            rules: [
                { test: /\.ts$/, include: /ClientApp/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader'] : '@ngtools/webpack' },
                { test: /\.html$/, use: 'html-loader?minimize=false' },
                { test: /\.css$/, use: ['to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize'] },
                // add scss loader
                {
                    test: /\.scss$/,
                    use: [
                        {
                            loader: 'file-loader',
                            options: {
                                name: 'bundle.css',
                            },
                        },
                        { loader: 'extract-loader' },
                        { loader: 'css-loader' },
                        { loader: 'sass-loader' },
                    ]
                },
                { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
            ]
        },
        plugins: [new CheckerPlugin()]
    };
...

and

...
            // Plugins that apply in production builds only
            new webpack.optimize.UglifyJsPlugin(),
            new AngularCompilerPlugin({                                     // replace AotPlugin with AngularCompilerPlugin
                tsConfigPath: './tsconfig.json',
                entryModule: path.join(__dirname, 'ClientApp/app/app.browser.module#AppModule'),
                exclude: ['./**/*.server.ts']
            })
...

and

...
        ].concat(isDevBuild ? [] : [
            // Plugins that apply in production builds only
            new AngularCompilerPlugin({                                     // replace AotPlugin with AngularCompilerPlugin
                tsConfigPath: './tsconfig.json',
                entryModule: path.join(__dirname, 'ClientApp/app/app.server.module#AppModule'),
                exclude: ['./**/*.browser.ts']
            })
        ]),
...
  1. Edit tsconfig.json for typescript >=2.7.2
...

    "emitDecoratorMetadata": true,
    "strictPropertyInitialization": false, // add this line
    "skipDefaultLibCheck": true,
...
  1. Create ClientApp\styles.scss with this line
@import "~@angular-mdc/theme";      // Add this line
  1. Edit ClientApp/boot.browser.ts
...
import 'reflect-metadata';
import 'zone.js';
//import 'bootstrap';   // deactivate this line
import './styles.scss'; // add this line
...
  1. Edit ClientApp/boot.server.ts
...
return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => {
    const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
    const state = moduleRef.injector.get(PlatformState);
    //const zone = moduleRef.injector.get(NgZone);              // deactivated this line
    const zone: NgZone = moduleRef.injector.get(NgZone);        // add this line

    return new Promise<RenderResult>((resolve, reject) => {

...
  1. Create ClientApp\app\app.module.mdc.ts
import { NgModule } from '@angular/core';
import {
  MdcAppBarModule,
  MdcButtonModule,
  MdcCardModule,
  MdcCheckboxModule,
  MdcChipsModule,
  MdcDialogModule,
  MdcDrawerModule,
  MdcElevationModule,
  MdcFabModule,
  MdcFormFieldModule,
  MdcGridListModule,
  MdcIconModule,
  MdcIconToggleModule,
  MdcLinearProgressModule,
  MdcListModule,
  MdcMenuModule,
  MdcRadioModule,
  MdcRippleModule,
  MdcSelectModule,
  MdcSliderModule,
  MdcSnackbarModule,
  MdcSwitchModule,
  MdcTabModule,
  MdcTextFieldModule,
  MdcThemeModule,
  MdcToolbarModule,
  MdcTypographyModule,
} from '@angular-mdc/web';

@NgModule({
  exports: [
    MdcAppBarModule,
    MdcButtonModule,
    MdcCardModule,
    MdcCheckboxModule,
    MdcChipsModule,
    MdcDialogModule,
    MdcDrawerModule,
    MdcElevationModule,
    MdcFabModule,
    MdcFormFieldModule,
    MdcGridListModule,
    MdcIconModule,
    MdcIconToggleModule,
    MdcLinearProgressModule,
    MdcListModule,
    MdcMenuModule,
    MdcRadioModule,
    MdcRippleModule,
    MdcSelectModule,
    MdcSliderModule,
    MdcSnackbarModule,
    MdcSwitchModule,
    MdcTabModule,
    MdcTextFieldModule,
    MdcThemeModule,
    MdcToolbarModule,
    MdcTypographyModule,
  ]
})
export class MdcMaterialModule { }
  1. Edit app.shared.module.ts
...
import { RouterModule } from '@angular/router';

import { MdcMaterialModule } from './app.module.mdc'; // Add this line

import { AppComponent } from './components/app/app.component';
...

and import it:

...
    imports: [
        CommonModule,
        HttpModule,
        FormsModule,
        MdcMaterialModule, // Add this line
        RouterModule.forRoot([
            { path: '', redirectTo: 'home', pathMatch: 'full' },
            { path: 'home', component: HomeComponent },
            { path: 'counter', component: CounterComponent },
            { path: 'fetch-data', component: FetchDataComponent },
            { path: '**', redirectTo: 'home' }
        ])
    ]
...
  1. Edit ClientApp\app\components\app\app.component.html
<div class='container-fluid'>
    <div class='row'>
        <div class='col-sm-3'>
            <nav-menu></nav-menu>
        </div>
        <div class='col-sm-9 body-content'>
            <router-outlet></router-outlet>
        </div>
    </div>
    <!--Add this <a> Tag part-->
    <a mdc-button [primary]="true" [raised]="true">
        <i class="material-icons mdc-button__icon">add box</i>
        mdc Button
    </a>
    <!-- until here -->
</div>
  1. Clear/Empty/Delete all content in ClientApp\app\components\navmenu\navmenu.component.html This causes the malfunction of the buttons while sizing the browser-window

  2. Edit Views\Shared\_Layout.cshtml

...
    <base href="~/" />

    <!-- add this 2 lines -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i" rel="stylesheet">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

    <!-- deactivated this line -->
    @*<link rel="stylesheet" href="~/dist/vendor.css" asp-append-version="true" />*@

    <!-- add this line -->
    <link rel="stylesheet" href="~/dist/bundle.css" asp-append-version="true" />
...
  1. Edit Views\Home\Index.cshtml
@{
    ViewData["Title"] = "Home Page";
}

<!-- deactivate this lines -->

@*<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>

    <script src="~/dist/vendor.js" asp-append-version="true"></script>
    @section scripts {
        <script src="~/dist/main-client.js" asp-append-version="true"></script>
    }*@

<!-- add this lines -->

<app>Loading...</app>

@section scripts {
    <script src="~/dist/vendor.js" asp-append-version="true"></script>
    <script src="~/dist/main-client.js" asp-append-version="true"></script>
}
  1. Save all files and close VS2017
  2. Open Node.js command prompt and go to the project directory (where package.json is located)
  3. rmdir /S node_modules (repeat until everything is deleted)
  4. npm install
  5. npm run build:vd
  6. npm run build:dev
  7. Open VS2017 and the project
  8. Wait until npm restore (select npm output) is done

  9. Start the solution (F5) and click the button

lod
  • 3
  • 3

1 Answers1

0

Couple options to resolve ripple opacity issue. Downgrade node-sass to 4.7.2, or upgrade angular-mdc/web to latest v0.34.1.

Issue was related to variables in the ripple mixins not getting interpolated properly.

Hope this helps.

trimox
  • 16
  • 1
  • 2
  • Hi @trimox. Thanks for your advice. The ripple effect works now like it should as you described with node-sass 4.7.2 or mdc/web 0.34.1. Doesn't matter what changes. But, there is still the problem with the size of the window (chrome). Wenn i move the window for the page. It works until the window is 769px wide. From 770px and up, I can't click the button anymore. Please have a look at my demo-gif. Do you have also a idea for this? Thanks. – lod Apr 09 '18 at 05:45
  • Your welcome. Could you paste the contents of `import './styles.scss';`? – trimox Apr 09 '18 at 11:40
  • Its under point nr. 8. Its only one line. `@import "~@angular-mdc/theme";` – lod Apr 09 '18 at 13:18
  • Very interesting. I see the ripple is not working at 769px, but does the button respond to `(click)` events? I've been unable to duplicate using existing code, so if it's still a problem I'll walk through your steps and let ya know. – trimox Apr 09 '18 at 21:27
  • Its not fix at 769px. Sometimes its also at 768. But I can't find out when it changes. Seems randomly. Its not the Browser start-size and not the resolution of the monitor (I'm working in a VM where I can reduce the size). And no, no ripple means also no click-events. With the angular-mdc/web v0.33.1 sometimes the space for the click shift to right. So I could click only on the left side of the button, but not on the right. With v0.34.1 this shifting doesn't happen anymore. It behaves like described. Let me know, when I can help. – lod Apr 10 '18 at 04:33
  • I will create a git repo. Wait with the reproducing. I think its easier for you. Give me a day (I'm new to this stuff). – lod Apr 10 '18 at 05:13
  • Have a look at the git-repository: https://github.com/lod911/vs2017-Angluar-Template-with-mdc-web Hope you can find the reason. – lod Apr 10 '18 at 19:55
  • @lod good news. Nothing wrong with the MDC usage, the problem is the navbar div. The offending div is ` – trimox Apr 12 '18 at 00:11
  • Great! Thanks a lot for your investigation! I edited my post and changed also my repository...in case someone will find it, maybe it helps. – lod Apr 12 '18 at 18:26