What is the process for specifying a dependency on an ng-metadata module?

I am currently working on a project that is utilizing ng-metadata for creating a few Angular 1.5 modules. One of the test modules/components in this project has the following structure:

import { NgModule, Component, Inject, Input, Output, EventEmitter } from 'ng-metadata/core'
import { platformBrowserDynamic } from 'ng-metadata/platform-browser-dynamic'

@Component({
    selector: 'test',
    template: require('./test.template.html')
})
class TestComponent {

    @Input() type: string;

    constructor() {
        console.log(`test: ${this.type}`)
    }

}

@NgModule({
    declarations: [TestComponent]
})
class HeroModule {}

platformBrowserDynamic().bootstrapModule(HeroModule)

After successful compilation, I am now trying to incorporate this module into another project that does not utilize ng-metadata, but supports a compatible version of Angular.

Following the instructions provided by ng-metadata documentation, I have included the necessary shims and the JavaScript file containing the aforementioned module (generated via webpack). In my new project, I have created a separate module which needs to include the HeroModule as a dependency. However, my attempts have so far resulted in an

Error: $injector:nomod Module Unavailable
error being thrown by Angular.

If I am using ng-metadata for constructing my modules, what specific names should I use when listing them as dependencies in a different project?

Answer №1

After some careful reading of the documentation, I finally cracked the code on this issue!

I stumbled upon the solution in the Manual Angular 1 Bootstrap section of ng-metadata's documentation:

By manually creating an Angular 1 module from an ng-metadata @NgModule using the bundle helper function, you can still take advantage of ng2 components registration without the need for ng-metadata bootstrap.

Here is the snippet of code that made it all work for me:

// REMOVED platformBrowserDynamic().bootstrapModule(HeroModule)  
const Ng1AdminModule = bundle(HeroModule).name;
export const AppModule = angular.module('hero', [Ng1AdminModule]);

With this setup, my hero module was accessible to the my-consuming-module, just as I had anticipated. The bundle helper function turned out to be the missing piece of the puzzle.

Answer №2

Make sure you import the necessary modules from their specific locations and include them in your angular module

// Make sure 'angular' and 'angular-ui-router' are included in the 'map' section of systemjs.config.js
import * as angular from 'angular';
import * as uiRouter from 'angular-ui-router';
import { heroModule} from './hero.module';

angular.module('app',[ uiRouter, heroModule]);

For more information, please visit this link here

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

Issue with Vue and Laravel Form Validation failing to return 422 response

I've been working on validating form data using Laravel and Vue on the backend, but I'm facing an issue with receiving a 422 response. Within my controller function: $this->validate($request, [ 'name' => 'required' ...

Saving file with HTML download button results in only HTML document being saved

I am attempting to include a "download file" button on my gatsby website as shown below: <a href="../../images/project-logos/placeholder-company-logo.png" download="test" className="responsive-square project-logo" > <img sr ...

Node.js Discord Bot | Config File Manipulation for Improved Functionality

Currently, I am facing a challenge with understanding how my NodeJS bot can effectively read and write data to a config.json file. Additionally, I am unsure about how to identify arguments that are passed along with a Bot Command. With that in mind, I have ...

Enhance the HTML5 Canvas arc by redrawing it upon hover

I have a challenge with my arcs: the first one loads on page-load, the second one loads on mouse-over, and the third one loads on mouse-out. However, I want the mouse-over-out effect to happen repeatedly rather than just once as it currently does. For ref ...

directive not updating scope variable when input file changes [see plunker for example]

Having an issue with a directive that includes a file input. While attempting to update certain scope variables upon changing the file input, I noticed that the variables are not updating as expected. Oddly enough, uncommenting the timeout function seems t ...

Unable to link JavaScript to HTML file through script tag

Upon testing out a responsive nav bar, I encountered an issue with the JavaScript not connecting. Despite placing the script tag at the bottom of the body as recommended, it still fails to function. index.html <html lang="en"> <head> ...

How can I manually include a triangle in BufferGeometry using Three.js?

Recently, I've been exploring the quickest method to change a mesh's vertices using three.js. Through my experimentation, I discovered that modifying parts of mesh.geometry.attributes.position.array and then setting mesh.geometry.attributes.posit ...

Can TypeScript convert JavaScript files automatically using a compiler?

Is there a way to use TypeScript files like this? <script type="text/typescript"> // ... </script> I came across https://www.typescriptlang.org/play/index.html, which can compile TypeScript. What compiler does this website use? I tried ...

Having trouble with Vue 3 Component State not updating following an asynchronous operation?

Encountering challenges in my Vue 3 app when trying to update a component's state post an asynchronous operation. Here's what's happening: Within a component, there is a method called containerMoveHere that utilizes Socket.io for an async o ...

invoking a JavaScript function within an if statement

i'm working with two javascript functions 1. function ValidateGVEducation() { var grid = document.getElementById('<%= gvEducation.ClientID %>'); var ddlQuali, ddlUni, ddlInsti, ddlAreaS, ddlStat; ...

Unusual actions exhibited by GestureEvent.rotation in iOS webkit browsing

Utilizing JavaScript Gesture events, I've been able to detect multitouch pan/scale/rotation actions on an element within an HTML document. If you visit this URL with an iPad: , you'll be able to touch the element with two fingers and rotate it. ...

The compilation of the Electron/Angular application encountered an error due to the absence of the necessary http

I have been tasked with adding a feature to an existing Electron/Angular application that has not been worked on for some time. When I try to launch the app in development mode using ng serve I encounter the following error message: Your global Angular ...

A TypeScript interface or class

Just had a lively discussion with a coworker and wanted to get some clarification. When shaping an object in TS, should we use a class or an interface? If I need to ensure that a function returns an object of a specific type, which one is the best choice? ...

Is the indexOf() method in JavaScript required to search through all array elements in order to execute?

const arr = ['a','b','c']; for (let char of arr) { console.log(char); } In my analysis, the time complexity of the code above is O(n). const arr = ['a','b','c']; for (let char of arr) { con ...

Issue with applying value changes in Timeout on Angular Material components

I'm currently experimenting with Angular, and I seem to be struggling with displaying a fake progress bar using the "angular/material/progress-bar" component. (https://material.angular.io/components/progress-bar/) In my "app.component.html", I have m ...

Fine-tuning CSS layout based on perspective alteration

I am working with the following code: function exportTableToExcel(tableID, filename = ''){ var downloadLink; var dataType = 'application/vnd.ms-excel'; var tableSelect = document.getElementById(tableID); var tableHT ...

Tips for examining a rate-limited HTTP request function

I am trying to test a naive rate limiter I implemented in Node.js for making HTTP requests to an external service. The service has a limit of 10 requests per second, and I am facing timing issues with my current implementation. Despite being aware of the i ...

Save a newly uploaded image to Github utilizing NodeJS and the Github API

Struggling to upload an image to my Github repo using NodeJS and Github API has been a challenge for me. I have managed to create the SHA, Commit Tree, and all necessary steps, but the final hurdle is passing the image to the API and saving it as an actual ...

emulate clicking on a child component element within the parent component's test file

In my testing scenario, I encountered a challenge in simulating the click event of an element that exists in a child component from the parent test file. let card; const displayCardSection = (cardName) => { card = cardName; }; describe('Parent ...

Obtain the Text Content from a Knockout Dropdown Menu

Currently, I am facing an issue with extracting the text value of a selected option from a dropdown menu on my webpage. The dropdown contains various image categories and is defined as follows: <select class="form-control" data-bind="options: imageCate ...