Bundle Angular library exports along with its corresponding models

I am in the process of developing an angular library for our company's private npm repository. Within this library, I aim to export classes that are utilized (injected via @Input()) in the library components.

Here is a sample model:

export class AdsToolbarMenuItem {
    iconName: string;
    label: string;
    enabled: boolean = true;
    menuAction: () => void;

    constructor(init?: Partial<AdsToolbarMenuItem>) {
        Object.assign(this, init);
    }
}

To achieve this, I have exported all classes in the models folder in moduleExports.ts, as shown below:

export * from './ContactBox';
export * from './AdsToolbarMainActionItem';
export * from './AdsToolbarMenuItem';

Then, in the index.ts file, I included exports to my component's module along with a reference to these module exports:

export * from './lib/angular-components.module';
export * from './lib/models/modelExports';

After successfully packaging and publishing the library to the NPM repository, I installed it in another project using npm. I was able to import the main LibraryModule into my Angular project and use the exported components without any issues.

However, when attempting to utilize any of the exported models from the library, such as the code snippet below:

import { AdsToolbarMainActionItem } from '@ads-shared/ads.shared.angular/lib/models/AdsToolbarMainActionItem';
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  items: AdsToolbarMainActionItem[] = [];

  constructor() {
    this.items.push(new AdsToolbarMainActionItem({ iconName: 'save' }));
  }
}

An error message is received:

ERROR in ./src/app/app.component.ts Module not found: Error: Can't resolve '@ads-shared/ads.shared.angular/lib/models/AdsToolbarMainActionItem' in 'C:\SRDEV_npx\empty-angular-project\test\src\app'

If you can provide any assistance on this issue, it would be greatly appreciated.

Answer №1

To utilize these classes which are exported by your library, simply perform the following:

import { AdsToolbarMainActionItem } from '@ads-shared/ads.shared.angular';

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

Using a custom jQuery function within an Angular component class

I have a custom query function that I wrote in a JavaScript file located under the source folder (/src/assets/inlineedit.js) of my Angular application. Here is the content of the file: $.fn.inlineEdit = function(replaceWith, connectWith) { $(this).ho ...

"Unexpected Type Inference Issue: A variable initially defined as a string inexplicably transforms into 'undefined'

Currently, I am incorporating the await-to-js library for handling errors (specifically utilizing the to method from the library). In an intriguing scenario, the variable type shifts to string | undefined within a for..of loop, whereas outside of the loop ...

SCSS styling in Angular 2 - Enhance Your Web Design

After creating a SCSS mixin in my main root file, style.scss, I encountered an error when attempting to access it in my home component. The error message stated, "No mixin named gradient." In order to resolve this issue, I would appreciate guidance on whe ...

Attempting to update Typescript on Linux Mint using npm

I am currently using typescript 2.1.4 and npm version 6.7.0. Realizing that 2.1.4 is quite outdated, I decided to try and update it. Here are the steps I took, which unfortunately did not work: $ sudo npm update -g typescript $ tsc --version Vesion 2.1. ...

Warning: Unresolved promise: NullInjectorError encountered: StaticInjectorError(AppModule) when trying to use FormBuilder

I encountered an error in my Angular app when adding routes in gifts-routing.module.ts. The error disappears when I remove the routes, but I still need to implement routing. How can I resolve this issue? ERROR Error: Uncaught (in promise): NullInjectorErr ...

Issue with Angular 8: discrepancy between the value utilized in component.html and the value stored in component.ts (Azure application service)

Encountering a peculiar behavior in one of my Angular applications. In the component.html file, I aim to display "UAT" and style the Angular mat elements with a vibrant orange color when in UAT mode, while displaying them in blue without any mention of UAT ...

Step-by-step guide on installing a multitude of global packages using Yarn

yarn install -h indicates that the -g (global) option is now considered outdated. How can I specify that I want to globally install multiple packages from my existing package.json/yarn.lock files? Possible solutions: yarn global [command] offers command ...

Node installation failed due to npm encountering an ETIMEDOUT error

Recently, I've been encountering some obstacles while attempting to install npm on our office's laptop within a specific directory. An error message keeps popping up: npm ERR! code ETIMEDOUT npm ERR! syscall connect npm ERR! errno ETIMEDOUT np ...

What sets apart exporting a component from importing its module in another module?

When working with Angular, consider having both module A and module B. If I intend to utilize "A-component" within components of module B, what is the distinction between importing module A in Module B compared to including the "A-component" in the exports ...

Prevent selection based on function in Angular

I'm attempting to prevent certain options from being selected based on a specific method. For instance, let's say I have four options: A B C D In my method (let's use "x" as an example): if(name == A) { disable the selection for option A. ...

I am struggling to start an angular project

I'm encountering an issue with Angular 5. I installed Angular 5 using the command "npm install --save-dev @angular/cli@latest". However, when I attempt to check the version of Angular with "ng -v", I am getting the following message. ...

Utilizing Angular 8's Reactive Form to Transform Checkbox Event Output into a String Format

My form is reactive and includes a field called Status, which can have the values 'A' or 'I': this.form = this.formBuilder.group({ result_info: this.formBuilder.array([ this.getResultcontrols()]), stat ...

Assign the image source to the file path located in the data directory

Is there a way to dynamically set the src attribute of an <img> tag in an HTML file using a string path from a file? The path is retrieved from the cordova.file.dataDirectory Cordova plugin within Ionic2 (TypeScript) and it typically looks like this ...

How can I efficiently map an array based on multiple other arrays in JavaScript/TypeScript using ES6(7) without nested loops?

I am dealing with 2 arrays: const history = [ { type: 'change', old: 1, new: 2 }, { type: 'change', old: 3, new: 4 }, ]; const contents = [ { id: 1, info: 'infor1' }, { id: 2, info: 'infor2' }, { id: ...

What is the best way to differentiate between the content in the 'stories' and '.storybook' directories?

Overview Upon integrating Storybook.js with my existing Create-React-App project, I found that two new directories were created by default: .storybook src/stories This integration seemed to blur the lines between different aspects of my project, which g ...

The Angular application is unable to find any matching routes while operating on a secure HTTPS

I am facing an issue with my Angular application created using the Radzen IDE and hosted on IIS. There is an anchor tag in the application that links to a .Net API for downloading files. The href of the anchor tag is structured like this: https://[Angular ...

Following an update from typescript version 2.3.4 to 2.4.2, I encountered a compilation error stating, "The type definition file for 'reflect-metadata' cannot be found."

Recently, I encountered an issue with my React / Mobex application written in TypeScript and built by Webpack 1. Upon updating the TypeScript version from 2.3.4 to 2.4.2, an error started occurring. The error message reads: ERROR in C:\myproject&bsol ...

Tips for creating a coverage report using a gulp task in Angular 4

I've experimented with numerous plugins for setting up gulp tasks to create coverage reports in Angular 4, but none of them seem to be effective. The issue lies in the fact that most documentation is aimed at javascript files, whereas I am dealing wit ...

Issue encountered when updating npm to version 5.4.2: Unable to locate modules in ./node_modules/react-router-dom

When attempting to update my npm version from 3.10.10 to 5.4.2 and migrate react from 15.3.0 to 16.0, I deleted the node_modules folder and re-ran npm install. However, upon trying to run my application again, I encountered the following error: ERROR in ./ ...

How can Enums be utilized as a key type for transmitting properties in Vue?

After stumbling upon a helpful method on Stack Overflow that demonstrated how to use an enum to define an object, I decided to implement this in my Vue project. export enum Options { randSize = 'randomSized', timer = 'showTimer', ...