Angular5 material Paginator is not working - angular-material

I want to use MatPaginatorModule in my angular t project but i am getting error:
Can't bind to 'pageSize' since it isn't a known property of 'mat-paginator'
1. If 'mat-paginator' is an Angular component and it has 'pageSize' input, then verify that it is part of this module.
...............
html
<mat-paginator #paginator
[pageSize]="10"
[pageSizeOptions]="[5, 10, 20]"
[showFirstLastButtons]="true">
</mat-paginator>
i have imported module in my app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { AppComponent } from './app.component';
import { GlobalModule } from './global/global.module';
import { ProtectedModule} from './protetcted/protect-module.component';
import { AppRoutingModule } from './app.routing.module';
// import { MatTableModule } from '#angular/material/table';
import { MatPaginatorModule } from '#angular/material';
#NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
GlobalModule,
ProtectedModule,
AppRoutingModule,
// MatTableModule,
MatPaginatorModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
i am using angular5
package.json
{
"name": "eci",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "node app.js",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.2.10",
"#angular/cdk": "^5.2.5",
"#angular/common": "^5.2.0",
"#angular/compiler": "^5.2.0",
"#angular/core": "^5.2.0",
"#angular/forms": "^5.2.0",
"#angular/http": "^5.2.0",
"#angular/material": "^5.2.5",
"#angular/platform-browser": "^5.2.0",
"#angular/platform-browser-dynamic": "^5.2.0",
"#angular/router": "^5.2.0",
"angular-font-awesome": "^3.1.2",
"bootstrap": "^4.1.0",
"cfenv": "^1.0.4",
"core-js": "^2.4.1",
"express": "^4.15.0",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"#angular/cli": "~1.7.2",
"#angular/compiler-cli": "^5.2.0",
"#angular/language-service": "^5.2.0",
"#types/jasmine": "~2.8.3",
"#types/jasminewd2": "~2.0.2",
"#types/jquery": "^3.3.1",
"#types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"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": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
}

#Kumail,
Everything looks fine from the snippets you posted.
Though this error will occur only when the required module is not linked. The only reason I could think of is that, you might not have saved app.module.ts file after modifications. I did follow all the steps to integrate a MatPaginatorModule in a test project and it worked. Then I mocked to include that module in app.module.ts but not saved the changes. This time I got the error you posted. Try saving, If you could have missed after modifying app.module.ts file.

If the error is coming while doing testing, then the imports are needed in the test/spec file. (app.component.spec.ts)

Related

Angular Material: material-nav generate does not working

I want to create a responsive side nav. I watched a video on youtube.
click here to see that video
After, I enter below command to the terminal
ng generate #angular/material:material-nav -name=nav
But it give an error as below,
Unknown option: '-e'
How to resolve that?
My Package.json as below,
{
"name": "euc",
"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",
"bootstrap": "^4.4.1",
"hammerjs": "^2.0.8",
"rxjs": "~6.4.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"
}
}
Angular CLI flags start with a double dash.
ng generate #angular/material:material-nav --name=nav

Can't add material to angular module

I try to find how to add angular material to work with angular divided into modules. It's work only in root, but not in modules.
ng add #angular/material
package.json
"dependencies": {
"#angular/animations": "^9.1.0-rc.2",
"#angular/cdk": "^9.1.3",
"#angular/common": "~9.1.0-rc.1",
"#angular/compiler": "~9.1.0-rc.1",
"#angular/core": "~9.1.0-rc.1",
"#angular/forms": "~9.1.0-rc.1",
"#angular/material": "^9.1.3",
"#angular/platform-browser": "~9.1.0-rc.1",
"#angular/platform-browser-dynamic": "~9.1.0-rc.1",
"#angular/router": "~9.1.0-rc.1",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.901.0-rc.0",
"#angular/cli": "~9.1.0-rc.0",
"#angular/compiler-cli": "~9.1.0-rc.1",
"#angular/language-service": "~9.1.0-rc.1",
"#types/node": "^12.11.1",
"#types/jasmine": "~3.5.0",
"#types/jasminewd2": "~2.0.3",
"codelyzer": "^5.1.2",
"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"
}
home.module.ts
import { CommonModule } from '#angular/common';
import { NgModule } from '#angular/core';
import { BrowserAnimationsModule } from '../../../node_modules/#angular/platform-browser/animations';
import { HomeRoutingModule } from './home-routing.module';
import { HomeComponent } from './home/home.component';
import { MatCardModule } from '#angular/material/card';
#NgModule({
declarations: [HomeComponent],
imports: [
CommonModule,
HomeRoutingModule,
MatCardModule,
BrowserAnimationsModule,
],
})
export class HomeModule { }
and my home.component.html
<p>home works!</p>
<mat-card>Simple card</mat-card>
it give me error:
ERROR in src/app/home/home/home.component.html:2:1 - error NG8001: 'mat-card' is not a known element:
1. If 'mat-card' is an Angular component, then verify that it is part of this module.
2. If 'mat-card' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '#NgModule.schemas' of this component
to suppress this message.
I tried to import material card module to app.module.ts. But then it's works only in root component, not in module.

Packaging app for platform win32 x64 taking too long using electron v5.0.6

I developped a web app with angular i need to package my web app using electron , it all seems fine until i run electron-packager , it takes forever , i dont know if it is supposed to be this slow or is there something wrong ?
ps : im on windows 7
this is my package.json
{
"name": "recherche-final",
"version": "0.0.0",
"main": "main.js",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"electron": "electron .",
"electron-build": "ng build && electron .",
"pack": "electron-packager."
},
"private": true,
"dependencies": {
"#angular/animations": "^6.0.3",
"#angular/cdk": "^6.2.0",
"#angular/common": "^6.0.3",
"#angular/compiler": "^6.0.3",
"#angular/core": "^6.0.3",
"#angular/forms": "^6.0.3",
"#angular/http": "^6.0.3",
"#angular/material": "^6.4.2",
"#angular/platform-browser": "^6.0.3",
"#angular/platform-browser-dynamic": "^6.0.3",
"#angular/router": "^6.0.3",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.6.8",
"#angular/cli": "~6.0.8",
"#angular/compiler-cli": "^6.0.3",
"#angular/language-service": "^6.0.3",
"#types/jasmine": "~2.8.6",
"#types/jasminewd2": "~2.0.3",
"#types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"electron": "^5.0.6",
"electron-packager": "^14.0.1",
"electron-winstaller": "^3.0.4",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~2.7.2"
}
}
i expect my app.exe
I know this is a late answer but just in case it helps anybody else- Have you checked how you have packaged your app? Make sure that your package.json files for angular and Electron are different. You are probably packing all the angular node modules as well into the electron application which is not necessary.
https://medium.com/#hellobharadwaj/electron-plus-angular-react-why-use-2-different-package-json-files-361ae47d07f3

Why bootstrap not getting loaded properly at Angular CLI MVC based project

I dont know whay bootstrap is not loaded properly at angular CLI Typescript based ASP.NET MVC based project. Somehow, seems default CSS files are overriden or i dont know exactly about the problem and no idea how to figure it out. I almost tried all solutions available on stackoverflow.com
For example following Bootstrap snippet not showing panel headers.
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">Panel heading</div>
<div class="panel-body">
<p>...</p>
</div>
</div>
I just created Angular app via CLI and modified package.json within the app. I did not copied the whole content at root folder.
So my solution structure is :
Moreover, part of angular.json is :
"schematics": {
"#schematics/angular:component": {
"styleext": "scss"
}
},
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"assets": [
"src/favicon.ico",
"src/assets"
],
"index": "src/index.html",
"main": "src/main.ts",
"outputPath": "../wwwroot/dist",
"polyfills": "src/polyfills.ts",
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
],
"styles": [
"node_modules/bootstrap/scss/bootstrap.scss"
"src/styles.scss"
],
"tsConfig": "src/tsconfig.app.json"
},
.............
and packages.json is :
"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": "^7.1.3",
"#angular/cdk": "^7.1.1",
"#angular/common": "~7.1.0",
"#angular/compiler": "~7.1.0",
"#angular/core": "~7.1.0",
"#angular/forms": "~7.1.0",
"#angular/material": "^7.1.1",
"#angular/platform-browser": "~7.1.0",
"#angular/platform-browser-dynamic": "~7.1.0",
"#angular/router": "~7.1.0",
"core-js": "^2.5.4",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26",
"bootstrap": "4.1.3",
"jquery": "^3.3.1"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.11.0",
"#angular/cli": "~7.1.3",
"#angular/compiler-cli": "~7.1.0",
"#angular/language-service": "~7.1.0",
"#types/jasmine": "~2.8.8",
"#types/jasminewd2": "~2.0.3",
"#types/jquery": "^3.3.27",
"#types/node": "~8.9.4",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.6"
}
Any body can let me know how to resolve this frustrating functioning error?
Since from what I can tell you don't even need the scss in your compile pipeline and you just need the css, change this;
"styles": [
"node_modules/bootstrap/scss/bootstrap.scss"
"src/styles.scss"
],
to this;
"styles": [
"./node_modules/bootstrap/dist/css/bootstrap.min.css"
"src/styles.scss"
],
...and ya should be good. Cheers.

Issue while running ASP Dot net core 2.0 - MVC 6 application with angular 4 material

I have created a ASP.Net Core Web application like in image with Angular. After successful creation of application, the solution run fine and output came in browser perfectly.
After, I have included angular material to the above project. Below is package.json
.{
"name": "WebApplication1",
"private": true,
"version": "0.0.0",
"scripts": {
"test": "karma start ClientApp/test/karma.conf.js"
},
"devDependencies": {
"#angular/animations": "5.0.2",
"#angular/common": "5.0.2",
"#angular/compiler": "5.0.2",
"#angular/compiler-cli": "5.0.2",
"#angular/core": "5.0.2",
"#angular/forms": "5.0.2",
"#angular/http": "5.0.2",
"#angular/platform-browser": "5.0.2",
"#angular/platform-browser-dynamic": "5.0.2",
"#angular/platform-server": "5.0.2",
"#angular/router": "5.0.2",
"#angular/cdk": "5.0.1",
"#angular/material": "^5.0.0-rc.3",
"#ngtools/webpack": "1.5.0",
"#types/chai": "4.0.1",
"#types/jasmine": "2.5.53",
"#types/webpack-env": "1.13.0",
"angular2-router-loader": "0.3.5",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "3.2.1",
"bootstrap": "3.3.7",
"chai": "4.0.2",
"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",
"jasmine-core": "2.6.4",
"jquery": "3.2.1",
"json-loader": "0.5.4",
"karma": "1.7.0",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.1.0",
"karma-webpack": "2.0.3",
"preboot": "4.5.2",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.10",
"rxjs": "5.5.5",
"style-loader": "0.18.2",
"to-string-loader": "1.1.5",
"typescript": "2.4.1",
"url-loader": "0.5.9",
"webpack": "2.5.1",
"webpack-hot-middleware": "2.18.2",
"webpack-merge": "4.1.0",
"zone.js": "0.8.18"
},
"dependencies": {
"#angular/cdk": "^5.0.1"
}
}
After installing angular material using npm, I have added all angular/material module import code in app.server.module.ts. Like below:
import { MatFormFieldModule } from '#angular/material';
And imported MatFormFieldModule into NgModule.
And my html is like:
<mat-form-field>
<textarea matInput placeholder="Leave a comment"></textarea>
</mat-form-field>
Finally the below error is coming in browser:
"mat-form-field" is unknown element
Please help me to short out this issue.
Import below Modules into the app.server.module.ts.
import { NgModule } from '#angular/core';
import { MatInputModule, MatFormFieldModule } from '#angular/material';
#NgModule({
imports: [
MatInputModule,
MatFormFieldModule
],
})
export class serverModule {
}
Declare your component Eg. Index.component.ts is declared into your module like below.
#NgModule({
imports: [
MatInputModule,
MatFormFieldModule
],
declarations : [
IndexComponent.ts
]
})
export class serverModule {
}
Then into your Index.component.html write this.
<form class="example-form">
<mat-form-field class="example-full-width">
<input matInput placeholder="Favorite food" value="Sushi">
</mat-form-field>
<mat-form-field class="example-full-width">
<textarea matInput placeholder="Leave a comment"></textarea>
</mat-form-field>
</form>
Note. before all these steps you should setup angular material into your project .
For any module of angular material that you want to use into your project, you should first import it's Mat...Module into the module that you are working to.
just like above.

Resources