Below is the simple Angular 2 code that should show dialog box in the middle out of the box. Instead dialog box show at the bottom.
I am using "angular-cli": "1.0.0-beta.24" and "#angular/material": "^2.0.0-beta.1"
Can anybody help why this is happening?
import { Component } from '#angular/core';
import {MdDialog,MdDialogRef,MdDialogConfig} from '#angular/material';
#Component({
selector: 'app-root',
template: `
<md-sidenav-container style="width:200px;height:500px;">
<md-sidenav mode="side" opened="true" #sidenav>
<md-nav-list>
<a md-list-item (click)="newItem()">
New
</a>
<a md-list-item>
Refresh
</a>
<a md-list-item>
Delete
</a>
</md-nav-list>
</md-sidenav>
</md-sidenav-container>
`,
})
export class AppComponent {
title = 'app works!';
constructor(public dialog: MdDialog) {}
newItem()
{
let dialogRef=this.dialog.open(RecordDialogComponent);
dialogRef.afterClosed().subscribe(result => {
});
}
}
#Component({
selector: 'record-dialog',
template: ` <h1 md-dialog-title>New Item</h1>
<md-dialog-actions>
<button (click)="dialogRef.close('save')">Save</button>
<button md-dialog-close>Cancel</button>
</md-dialog-actions>
`
})
export class RecordDialogComponent{
public title: string;
public message: string;
constructor(public dialogRef: MdDialogRef<RecordDialogComponent>) { }
}
Below is the package.json
{
"name": "materialt2",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"#angular/common": "^2.3.1",
"#angular/compiler": "^2.3.1",
"#angular/core": "^2.3.1",
"#angular/forms": "^2.3.1",
"#angular/http": "^2.3.1",
"#angular/material": "^2.0.0-beta.1",
"#angular/platform-browser": "^2.3.1",
"#angular/platform-browser-dynamic": "^2.3.1",
"#angular/router": "^3.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"#angular/compiler-cli": "^2.3.1",
"#types/jasmine": "2.5.38",
"#types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.24",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.0.2",
"typescript": "~2.0.3"
}
}
Try this
const dialogRef = this.dialog.open(DialogComponentName, {
width: '250px'
position: { bottom: '0'}
});
You can also add left: 0 etc.
I had the same issue as you. This post helped me to solve it (although I think this isn't intended because it isn't described anywhere I looked): Angular2 Material: Md-Menu opens below router outlet
You need to include a theme from Angular Material as described here: https://github.com/angular/material2/blob/master/guides/theming.md
That fixed it for me.
You can change modal position using this code. Put this inside your md-dialog component.
import { MdDialog, MdDialogConfig, MdDialogRef } from '#angular/material';
constructor(public dialogRef: MdDialogRef<any>) { }
ngOnInit() {
this.dialogRef.updatePosition({ top: '25px', left: '25px' });
}
you can use updatePosition method anywhere inside dialog component.
for more information check this link https://material.angular.io/components/component/dialog
Related
I have two angular 9.1.1 project. The first one is to create an angular element and the other one is to use that element.
Node: v12.16.2
NPM: 6.14.4
package.json
{
"name": "angular-element",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build:elements": "ng build --prod --output-hashing none && node build-elements.js"
},
"private": true,
"dependencies": {
"#angular/animations": "~9.1.1",
"#angular/common": "~9.1.1",
"#angular/compiler": "~9.1.1",
"#angular/core": "~9.1.1",
"#angular/elements": "^10.0.0-next.2",
"#angular/forms": "~9.1.1",
"#angular/platform-browser": "~9.1.1",
"#angular/platform-browser-dynamic": "~9.1.1",
"#angular/router": "~9.1.1",
"#webcomponents/custom-elements": "^1.4.1",
"document-register-element": "^1.7.2",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.901.1",
"#angular/cli": "~9.1.1",
"#angular/compiler-cli": "~9.1.1",
"#angular/language-service": "~9.1.1",
"#types/jasmine": "~3.5.0",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"concat": "^1.0.3",
"fs-extra": "^9.0.0",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.4.1",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~3.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.8.3"
}
}
tsconfi.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
Code to concatenate build files in single file
const fs = require('fs-extra');
const concat = require('concat');
var f = []
var css = ""
fs.readdir("./dist/angular-element", function(err, items) {
for (let index = 0; index < items.length; index++) {
if(items[index].includes(".js")) {f.push("./dist/angular-element/" + items[index]);}
else if (items[index].includes(".css")) {
css = "./dist/angular-element/" + items[index];
}
}
build(f);
});
function build(files) {
fs.ensureDir('elements')
concat(files, 'elements/elements.js');
if(css != "") fs.copyFile(css, 'elements/styles.css')
}
Note:
Element works properly when you create dev build after dynamically embedding element. But it gives error while create production build using --prod in angular9.1.1
Code to dynamically adding element is:
private loader: boolean = false;
load(): void {
if (this.loader) { return; }
const path = '../../../../assets/libs/temp-web/elements.js';
const script = document.createElement('script');
script.src = path;
document.body.appendChild(script);
this.loader = true;
}
Error:
But in --prod build it gives an error.
I am not sure. You are doing everything corrent. I followed steps and I am able to create web component using angular elements.
When I run the following piece of code on my iOS emulator, the onTap() method is called twice. The exact same code run on my physical iPhone the onTap() is only called once. I know its the same code because tns run ios deploys to both simultaneously.
home.component.html:
<ActionBar title="Home" class="action-bar" visability="collapsed"></ActionBar>
<FlexboxLayout flexDirection="column" justifyContent="center" alignItems="center">
<Button (tap)="onTap($event)" class="fas btn btn-primary" text="Test"></Button>
</FlexboxLayout>
home.component.ts:
import { Component, OnInit } from '#angular/core';
import { Page } from 'ui/page';
#Component({
selector: 'home',
moduleId: module.id,
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
counter = 0;
constructor(private _page: Page) {}
ngOnInit(): void {
this._page.actionBarHidden = true;
}
onTap(args) {
this.counter++;
console.log('Tapped ' + this.counter + ' times!');
}
}
When I press button on emulator I get (note counter is not incremented):
CONSOLE LOG file:///app/app/home/home.component.js:15:20: Tapped 1 times!
CONSOLE LOG file:///app/app/home/home.component.js:15:20: Tapped 1 times!
Same code, on physical iPhone I get:
CONSOLE LOG file:///app/app/home/home.component.js:15:20: Tapped 1 times!
app-routing.module.ts:
const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{
path: 'test',
loadChildren: '~/app/test/test.module#TestModule',
data: {
title: 'Test'
}
}
];
#NgModule({
imports: [NativeScriptRouterModule.forRoot(routes)],
exports: [NativeScriptRouterModule]
})
export class AppRoutingModule {}
package.json:
"dependencies": {
"#angular/animations": "~7.1.0",
"#angular/common": "~7.1.0",
"#angular/compiler": "~7.1.0",
"#angular/core": "~7.1.0",
"#angular/forms": "~7.1.0",
"#angular/http": "~7.1.0",
"#angular/platform-browser": "~7.1.0",
"#angular/platform-browser-dynamic": "~7.1.0",
"#angular/router": "~7.1.0",
"nativescript-angular": "~7.1.0",
"nativescript-ngx-fonticon": "~4.2.0",
"nativescript-orientation": "~2.2.1",
"nativescript-sqlite": "~2.2.6",
"nativescript-theme-core": "~1.0.4",
"nativescript-ui-chart": "~3.11.1",
"nativescript-ui-listview": "~5.1.0",
"reflect-metadata": "~0.1.8",
"rxjs": "~6.3.0",
"tns-core-modules": "~5.1.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"#angular/compiler-cli": "~7.1.0",
"#nativescript/schematics": "~0.5.0",
"#ngtools/webpack": "~7.1.0",
"codelyzer": "~4.5.0",
"nativescript": "~5.1.0",
"nativescript-dev-sass": "~1.6.0",
"nativescript-dev-typescript": "~0.7.0",
"nativescript-dev-webpack": "~0.19.0",
"tslint": "~5.11.0"
},
Things I've tried:
Delete app from emulator
Delete hooks,node_modules,platforms and re-run tns run ios
Created a similar app in the playground, and everything is fine (onTap() is only called once on the emulator).
Any ideas?
It was something with filewatcher. Two instances of it running was deploying the same app 2x on device. Hard to explain.
I Hardware > Erase all content and settings.., killed my terminal, opened a new one and ran tns run ios.
After migrating from Angular 5 to Angular 6 all my Material component do not work anymore - again... ...yet this time I am really clueless about what could cause the problem anymore. I invested half a day investigating and created a stripped-down project in order to reproduce the problem in its essence.
Let me show you the various file contents:
package.json
{
"name": "xxx",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^6.0.9",
"#angular/cdk": "^6.4.0",
"#angular/common": "^6.0.9",
"#angular/compiler": "^6.0.9",
"#angular/core": "^6.0.9",
"#angular/forms": "^6.0.9",
"#angular/http": "^6.0.9",
"#angular/material": "^6.4.0",
"#angular/platform-browser": "^6.0.9",
"#angular/platform-browser-dynamic": "^6.0.9",
"#angular/platform-server": "^6.0.9",
"#angular/router": "^6.0.9",
"#ngtools/webpack": "1.8.0",
"#types/node": "~6.0.60",
"#types/webpack-env": "1.13.0",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "3.2.1",
"codelyzer": "~3.2.0",
"css": "2.2.1",
"css-loader": "0.28.4",
"es6-shim": "0.35.3",
"event-source-polyfill": "0.0.9",
"expose-loader": "0.7.3",
"extract-text-webpack-plugin": "2.1.2",
"file-loader": "0.11.2",
"html-loader": "0.4.5",
"isomorphic-fetch": "2.2.1",
"jquery": "3.2.1",
"json-loader": "0.5.4",
"preboot": "4.5.2",
"protractor": "~5.1.2",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.10",
"rxjs": "^6.2.2",
"style-loader": "0.18.2",
"to-string-loader": "1.1.5",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.7.2",
"url-loader": "0.5.9",
"webpack": "2.5.1",
"webpack-hot-middleware": "2.18.2",
"webpack-merge": "4.1.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"#angular/cli": "^6.0.8",
"#angular/compiler-cli": "^6.0.9",
"#angular/language-service": "^6.0.9",
"#types/node": "~6.0.60",
"codelyzer": "~3.2.0",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0"
}
}
app.module
import { NgModule } from '#angular/core';
import { MatDialogModule } from '#angular/material';
import { CommonModule } from '#angular/common';
import { RouterModule } from '#angular/router';
import { AppComponent } from './components/app/app.component';
import { MessageFormComponent } from './components/common/forms/message.component';
#NgModule({
declarations: [
AppComponent,
MessageFormComponent,
],
imports: [
CommonModule,
MatDialogModule,
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: MessageFormComponent },
{ path: '**', redirectTo: 'home' }
]),
]
})
export class AppModuleShared {
}
message.component.ts
import { Component } from '#angular/core';
import { MatDialog, MAT_DIALOG_DATA } from '#angular/material';
#Component({
selector: 'message-form',
template: 'blubb',
})
export class MessageFormComponent {
constructor(private alert: MatDialog) { } // this line causes the problem
}
As soon as I make ANYTHING with the material - this error occurs. I am good in programming angular programs - not so good in fiddling around with the NEVER WORKING infrastructure... ;-)
I am trying to use Mat-tree module in my angular application, but getting compile time error:
Argument of type '(node: TodoItemNode) => TodoItemNode[]' is not assignable to parameter of type '(node: TodoItemNode) => Observable'. Type 'TodoItemNode[]' is not assignable to type 'Observable'. Property '_isScalar' is missing in type 'TodoItemNode[]'
Here is the link from where I have referred or copied the code for demo UI:
Angular Material Official Mat-Tree Example Link
Here is the code where it throws an error:
Login Report Component:
constructor(
private database: ChecklistDatabase
) {
this.treeFlattener = new MatTreeFlattener(this.transformer, this.getLevel,
this.isExpandable, this.getChildren); // This line
this.treeControl = new FlatTreeControl<TodoItemFlatNode>(this.getLevel, this.isExpandable);
this.dataSource = new MatTreeFlatDataSource(this.treeControl, this.treeFlattener);
database.dataChange.subscribe(data => {
this.dataSource.data = data;
});
}
Edit:
transformer = (node: TodoItemNode, level: number) => {
const existingNode = this.nestedNodeMap.get(node);
const flatNode = existingNode && existingNode.item === node.item
? existingNode
: new TodoItemFlatNode();
flatNode.item = node.item;
flatNode.level = level;
flatNode.expandable = !!node.children;
this.flatNodeMap.set(flatNode, node);
this.nestedNodeMap.set(node, flatNode);
return flatNode;
}
And
getLevel = (node: TodoItemFlatNode) => node.level;
isExpandable = (node: TodoItemFlatNode) => node.expandable;
getChildren = (node: TodoItemNode): TodoItemNode[] => node.children;
MatTreeFlattener Constructor:
constructor(transformFunction: (node: T, level: number) => F, getLevel: (node: F) => number, isExpandable: (node: F) => boolean, getChildren: (node: T) => Observable<T[]>);
Package.Json
{
"name": "kalpavriksha-angular-v4",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#agm/core": "^1.0.0-beta.1",
"#agm/snazzy-info-window": "^1.0.0-beta.1",
"#angular/animations": "^5.0.0",
"#angular/cdk": "^6.0.0-beta.4",
"#angular/common": "^5.0.0",
"#angular/compiler": "^5.0.0",
"#angular/core": "^5.0.0",
"#angular/forms": "^5.0.0",
"#angular/http": "^5.0.0",
"#angular/material": "^6.0.0-beta.4",
"#angular/platform-browser": "^5.0.0",
"#angular/platform-browser-dynamic": "^5.0.0",
"#angular/platform-server": "^5.0.0",
"#angular/router": "^5.0.0",
"#swimlane/ngx-charts": "^6.1.0",
"#types/filesaver": "0.0.30",
"angular-chat": "^1.0.9",
"angular-datatables": "^4.2.0",
"angular-file-picker": "^1.2.0",
"angular-file-saver": "^1.1.3",
"angular-material": "^1.1.5",
"angularfire2": "5.0.0-rc.3",
"angularjs-bootstrap-datetimepicker": "^1.1.4",
"chart.js": "^2.7.2",
"chart.piecelabel.js": "^0.11.0",
"cloudboost": "^2.0.264",
"core-js": "^2.4.1",
"d3": "^4.11.0",
"datatables.net": "^1.10.16",
"datatables.net-buttons": "^1.4.2",
"datatables.net-buttons-dt": "^1.4.2",
"datatables.net-dt": "^1.10.16",
"datatables.net-select": "^1.2.3",
"datatables.net-select-dt": "^1.2.3",
"file-saver": "^1.3.3",
"firebase": "4.6.0",
"hammerjs": "^2.0.8",
"material-design-icons": "^3.0.1",
"md-date-picker": "^0.1.0",
"ng-chat": "^1.0.12",
"ng-snotify": "^4.0.0",
"ng2-charts": "^1.6.0",
"ng2-search-filter": "^0.3.1",
"ng4-loading-spinner": "^1.0.27",
"ngx-cookie-service": "^1.0.9",
"ngx-inactivity": "^1.0.1",
"ngx-loading": "^1.0.7",
"ngx-pagination": "^3.1.0",
"ngx-progress-bar": "0.0.10",
"rxjs": "^5.5.11",
"snazzy-info-window": "^1.1.0",
"time-ago-pipe": "^1.3.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"#angular/cli": "^1.4.1",
"#angular/compiler-cli": "^5.0.0",
"#angular/language-service": "^4.0.0",
"#types/datatables.net": "^1.10.6",
"#types/jasmine": "~2.5.53",
"#types/jasminewd2": "~2.0.2",
"#types/jquery": "^3.2.12",
"#types/node": "~6.0.60",
"codelyzer": "~3.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"typescript": "2.4.2"
}
}
I was also getting the same Error for MAT-TREE
Solved by updating the Angular Material # package.json and Delete the Node Modules and npm install.
From "#angular/material": "^6.2.0" to=> "#angular/material": "^6.4.2"
Here is my package.json:
{
"name": "DFS",
"version": "1.0.0",
"description": "DFS App",
"author": "asd",
"private": true,
"nodemonConfig": {
"delay": "2500"
},
"scripts": {
"postinstall": "npm run build",
"dev": "node build/dev-server.js",
"start": "node build/dev-server.js",
"build": "node build/build.js",
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
"e2e": "node test/e2e/runner.js",
"test": "npm run unit && npm run e2e",
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs",
"deploy": "git subtree push --prefix dist heroku master"
},
"dependencies": {
"axios": "^0.16.2",
"connect-history-api-fallback": "^1.5.0",
"express-sslify": "^1.2.0",
"global": "^4.3.2",
"heroku-ssl-redirect": "0.0.4",
"less": "^3.0.1",
"less-loader": "^4.0.5",
"node-sass": "^4.7.2",
"npm-watch": "^0.3.0",
"sass-loader": "^6.0.6",
"style-loader": "^0.20.2",
"vee-validate": "^2.0.0-rc.14",
"vue": "^2.3.3",
"vue-router": "^2.3.1",
"vuetify": "^1.0.3",
"vuex": "^3.0.1",
"webpack-dev-server": "^3.0.0",
"webpack-watch": "^0.2.0"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-eslint": "^7.1.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-istanbul": "^4.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"chai": "^3.5.0",
"chalk": "^2.0.1",
"chromedriver": "^2.27.2",
"connect-history-api-fallback": "^1.3.0",
"copy-webpack-plugin": "^4.0.1",
"cross-env": "^5.0.1",
"cross-spawn": "^5.0.1",
"css-loader": "^0.28.0",
"cssnano": "^3.10.0",
"eslint": "^3.19.0",
"eslint-config-standard": "^6.2.1",
"eslint-friendly-formatter": "^3.0.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-html": "^3.1.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"eslint-plugin-vue": "^4.0.0",
"eventsource-polyfill": "^0.9.6",
"express": "^4.14.1",
"extract-text-webpack-plugin": "^2.0.0",
"file-loader": "^0.11.1",
"friendly-errors-webpack-plugin": "^1.1.3",
"html-webpack-plugin": "^2.28.0",
"http-proxy-middleware": "^0.17.3",
"inject-loader": "^3.0.0",
"karma": "^1.4.1",
"karma-coverage": "^1.1.1",
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-phantomjs-shim": "^1.4.0",
"karma-sinon-chai": "^1.3.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.31",
"karma-webpack": "^2.0.2",
"lolex": "^2.0.0",
"mocha": "^3.2.0",
"nightwatch": "^0.9.12",
"node-notifier": "^5.1.2",
"opn": "^5.1.0",
"optimize-css-assets-webpack-plugin": "^2.0.0",
"ora": "^1.2.0",
"phantomjs-prebuilt": "^2.1.15",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"rimraf": "^2.6.0",
"selenium-server": "^3.0.1",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"sinon": "^2.1.0",
"sinon-chai": "^2.8.0",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.1",
"sw-precache-webpack-plugin": "^0.11.4",
"ts-loader": "^3.5.0",
"uglify-es": "^3.0.25",
"url-loader": "^0.5.8",
"vue-loader": "^12.1.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.3.3",
"webpack": "^2.6.1",
"webpack-bundle-analyzer": "^2.2.1",
"webpack-cli": "^2.0.9",
"webpack-dev-middleware": "^1.10.0",
"webpack-hot-middleware": "^2.18.0",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 4.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
My main.js:
import Vue from 'vue'
import Vuetify from 'vuetify' // eslint-disable-line no-unused-vars
// import App from './App'
// import router from './router'
Vue.use(Vuetify)
// Vue.config.productionTip = false
new Vue({ // eslint-disable-line no-new
el: '#app',
// router,
template: '<div>hi there</div>'
// components: { App },
// template: '<App/>'
})
My App.vue
<template>
<div>
123
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
I am using Heroku for the app hosting. When I try to visit site with desktop browser all is okay, but when I try to load it via mobile browser it shows the blank page.
For the other hand deploying this repo: https://github.com/deepak-singh/vue-blog-pwa
is successfully done and loading via mobile or desktop browser is successful.
Also I found that this line causes blank page in my vue app:
Vue.use(Vuetify)
But! This line is present in vue-pwa-blog repo file. So I can not understand what may I doing wrong?
This is happening because when a PWA is installed and opened on a phone it rewrites the URL to /index.html whereas the vuetify app is rendered at /.
Just re-adjust your vue-router to load the component at /index.html too and it should work.
Your router.js could look something like this:
{
path: '/',
name: 'App',
component: App
},
{
path: '/index.html',
name: 'App',
component: App
}
My routers are like this:
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '#/components/HelloWorld'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'HelloWorld',
component: HelloWorld
},
{
path: '/index.html',
name: 'HelloWorld',
component: HelloWorld
}
]
})
Still blank page.. If i remove my Vue.use(Vuetify) from main.js works..
Package.json ->
"dependencies": {
"vue": "^2.5.2",
"vue-router": "^3.0.1",
"vuetify": "^1.1.6"
},