Incorporating Material and Formly components into an Angular library

While attempting to develop an Angular 9 library that incorporates Material and Formly modules, I am encountering difficulties in configuring it.

Within the library:

core-ui.module.ts

/**
 * Angular Core
 */
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FlexLayoutModule } from '@angular/flex-layout';
import { RouterModule } from '@angular/router';

/**
 * Third Party libs
 */
import { AppFormlyModule } from './modules/formly.module';
import { MaterialModule } from './modules/material.module';

/**
 * Custom Components and Services
 */
import { DataTableComponent } from './components/data-table/data-table.component';
import { FormMasterComponent } from './components/form-master/form-master.component';
import { SiteNavComponent } from './components/site-navigation/site-navigation.component';
import { UiBlockerComponent } from './components/ui-blocker/ui-blocker.component';
import { ViewMasterComponent } from './components/view-master/view-master.component';

@NgModule({
  declarations: [
    UiBlockerComponent,
    ViewMasterComponent,
    FormMasterComponent,
    SiteNavComponent,
    DataTableComponent,
  ],
  exports: [
    CommonModule,
    RouterModule,
    MaterialModule,
    AppFormlyModule,
    UiBlockerComponent,
    ViewMasterComponent,
    FormMasterComponent,
    SiteNavComponent,
    DataTableComponent,
  ],
  imports: [
    CommonModule,
    RouterModule,
    MaterialModule,
    AppFormlyModule,
    FlexLayoutModule,
    AppFormlyModule,
  ],
  providers: [
    DataTableComponent,
  ],
})
export class CoreUIModule { }

material.module.ts

import { ModuleWithProviders, NgModule} from "@angular/core";
import { MAT_LABEL_GLOBAL_OPTIONS, MatNativeDateModule, MAT_DATE_LOCALE } from '@angular/material/core';
import { MatIconRegistry } from '@angular/material/icon';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
.
.
. (Text has been shortened for brevity)
.
.
@NgModule({
    imports: [
        MatAutocompleteModule,
        MatBadgeModule,
        MatButtonModule,
        MatButtonToggleModule,
        MatCardModule,
        MatCheckboxModule,
        MatChipsModule,
        MatStepperModule,
        MatDatepickerModule,
        MatDialogModule,
        MatExpansionModule,
        MatFormFieldModule,
        MatGridListModule,
        MatIconModule,
        MatInputModule,
        MatListModule,
        MatMenuModule,
        MatPaginatorModule,
        MatProgressBarModule,
        MatProgressSpinnerModule,
        MatRadioModule,
        MatRippleModule,
        MatSelectModule,
        MatSidenavModule,
        MatSliderModule,
        MatSlideToggleModule,
        MatSnackBarModule,
        MatSortModule,
        MatTableModule,
        MatTabsModule,
        MatToolbarModule,
        MatTooltipModule,
        MatTreeModule,
        MatNativeDateModule
    ],
    exports: [
        MatAutocompleteModule,
        MatBadgeModule,
        MatButtonModule,
        MatButtonToggleModule,
        MatCardModule,
        MatCheckboxModule,
        MatChipsModule,
        MatStepperModule,
        MatDatepickerModule,
.
.
. (Text has been shortened for brevity)
.
.
])
export class MaterialModule {
    constructor(public matIconRegistry: MatIconRegistry) {
      //  matIconRegistry.registerFontClassAlias('fontawesome', 'fa');
    }

    static forRoot(): ModuleWithProviders<MaterialModule> {
        return {
            ngModule: MaterialModule,
            providers: [MatIconRegistry]
        };
    }
}

formly.module.ts

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { FormlyModule } from '@ngx-formly/core';
.
.
. (Text has been shortened for brevity)
.
.
export class AppFormlyModule {}

Then, within the app, I import the core module:

import { CoreUIModule } from 'core-ui';

However, when compiling the app, I encounter errors indicating issues with Dependency Injection (DI) that are proving challenging to resolve.

NG8002: Can't bind to 'pageSizeOptions' since it isn't a known property of 'mat-paginator'. 1. If 'mat-paginator' is an Angular component and it has 'pageSizeOptions' input, then verify that it is part of this module. 2. If 'mat-paginator' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. 3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.

Note: For testing purposes, I am utilizing a local distribution file for the test application: "core-ui": "file:../core.ui/dist/core-ui/core-ui-0.0.2.tgz"

Answer №1

To ensure proper functionality, make sure to add MatPaginatorModule into your formly.module.ts file:


...
@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    MaterialModule,
    MatInputModule,
    ReactiveFormsModule,
    MatAutocompleteModule,
    MatPaginatorModule,
...

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

Implementing asynchronous image loading with Angular 4 using bearer headers

Currently, I am working on making asynchronous image requests with authentication headers. The image paths in the code look like this: <img src="{{file.src}}"/> I need to include a Bearer Token in the header for these requests, but since there are ...

What methods are available to change one JSON format into another?

I am receiving JSON data from a Laravel API in the following format: [ { "id":48, "parentid":0, "title":"Item 1", "child_content":[ { "id":49, "parentid":48, "title":"Itema 1 ...

How to Access Data Attribute in React TypeScript on Click Event

Recently, I encountered a situation with my React component where I have a button with a click handler that utilizes the data-* attribute. In the past, with regular React, extracting the value from the data-* attribute was straightforward. However, as I am ...

Steps to troubleshoot a simple function that manages asynchronous tasks

Looking to develop a versatile function that can handle async functions, execute them, and catch any errors that may arise. Coming from a javascript background, I initially managed to create a function that did just this. However, my attempt to enhance it ...

Deleting a parent item along with its child elements in the ngrx state management library

I am currently exploring ngrx store and grappling with where to place my logic, specifically whether looping through an array should be handled in the reducer or the component. I have an array of objects called Item that need to be manipulated - particular ...

Exploring project references in TypeScript 3 with distinct `outDir` configurations

I am eager to utilize the project references functionality in TypeScript 3.1. Initially, my project's directory structure post-compilation appears as follows: . ├── A │ ├── a.ts │ ├── dist │ │ ├── A │ │ ...

How to stop a component template in Angular from displaying both conditional statements simultaneously?

I want to prevent my component template from briefly displaying both conditional statements when the condition changes after the component has been initialized. My application receives a token, and depending on its validity, it shows the appropriate conte ...

Converting an array of date strings to a single string in JavaScript

Here is the JSON format I received with dynamic data: {"range":["2018-07-23T16:03:26.861Z","2018-07-23T16:03:26.861Z"]} Now, I need to convert this into the following format: range(20180723,20180723) Below is my code snippet : var data:Date[] = {"rang ...

Typescript library available as a private npm dependency

I have developed a Typescript library that I bundle as an npm module. During the development of my frontend application, I easily integrated this library using yarn link. As I set up GitLab CI for other developers to work on the frontend application, I am ...

Can you clarify the definition of component initialization in Angular 2+ specifically in relation to the OnInit lifecycle hook?

As per the Angular documentation on Life cycle hooks at Angular.io, the OnInit hook serves to initialize the directive/component after Angular has initially displayed its data-bound properties and set its input properties. But what exactly occurs when it& ...

Utilizing ASP.NET Core MVC in conjunction with Angular and Identity Server 4 for seamless integration with web API connections

Posting here after receiving a response from this post -------------------------------------- In the midst of developing an application with an MVC core app that loads an angular application. The angular app will connect to a Web API for CRUD operations. ...

When utilizing Typescript with React Reduxjs toolkit, there seems to be an issue with reading the state in useSelector. An error message is displayed indicating that the variable loggedIn

I have encountered an error while passing a state from the store.tsx file to the component. The issue lies in the const loggedIn where state.loggedIn.loggedIn is not recognized as a boolean value. Below is the code snippet for the component: import React ...

Tips for enforcing a mandatory type with TypeScript

Creating a custom type called InputType with optional properties like this: export type InputType = { configJsonUrl?: string; configJsObject?: DataType; rawData?: { [key: string]: string }; action?: () => void; }; export type DataType = { id ...

The Angular Material Tree component is not rendering properly in an Angular tutorial demonstration

Upon completing the installation of @angular/material, @angular/cdk, and @angular/animations through npm install --save, I attempted to reconstruct the flat tree example provided by Angular. Unfortunately, even after addressing the error message stating Co ...

A technique for adding a border to a Mat Card that mimics the outline of a Mat Form Field within a custom

I am faced with a unique design challenge where I am utilizing the MatCardComponent and each card contains a table. I would like to incorporate a floating label within the border gap similar to what is seen in MatFormField. https://i.stack.imgur.com/51LBj ...

How can ngValue be leveraged with Angular Material's autocomplete feature?

I need to pass an object as my value and use [ngValue] instead of [value]. This is how my HTML is structured: <mat-input-container fxFlex="18" fxFlexOffset="1"> <input matInput placeholder="Example" [matAutocomplete]= ...

I believe my routing may be incorrect. Alternatively, the issue might lie elsewhere

I am facing an issue with Angular routing, where I want the navigation bar to persist while changing the background. However, the navigation bar overlaps on top of the background when I try to achieve this. [! [Check out my routing file] (https://i.stack. ...

Auto increment package.json version in a monorepo configuration

I am working on an Angular 6 app configured as a monorepo, comprising of a project that needs to be published to NPM along with a demo app. To update the versions of both the application and the project, I would like to utilize the npm version command. Th ...

Excluding the decimal point from version 1.0 in an API response with Angular 5

When working with Angular 5, I encountered an issue where the API response was returned as 1.0, but when displayed in the HTML field it only showed as 1. Upon inspecting the response in Chrome dev-tools, under the Network tab -> Response, it correctly ...

How can I showcase the captured image on Ionic 2?

I am having trouble displaying the selected or captured image on the page after uploading it through two methods - one using the gallery and the other using the camera. ** Here is my code ** 1) profile.html: <img class="profile-picture" src="{{baseUr ...