Configuring Systemjs to properly load the templateUrl in Angular2ORSetting

I am facing an issue with systemjs while working with angular2.

index.html

System.config({
     packages: {
       'app': {
               format: 'register',
               defaultExtension: 'js'
        },
        'angular2': {
                defaultExtension: 'js'
        },
        'rxjs': {
               defaultExtension: 'js'
        }
    },
    paths: {
        '*': 'dist/*',
        'app/*': 'dist/app/*',
        'angular2/*': 'node_modules/angular2/*',
        'rxjs/*': 'node_modules/rxjs/*'
    }
});

System.import('app/main.js').then(null, console.error.bind(console));    

app.js

import {NavbarComponent} from './components/navbar/navbar';
@Component({
    selector: 'main-app',
    templateUrl: './app/app.html',
    directives: [RouterOutlet, NavbarComponent]
})

This is the structure:

https://i.sstatic.net/bkcow.png

When I run serve:

dev: {
        port: 8080,
        host: "127.0.0.1",
        open: '/',
        root: '.',
        file: "index.html",
        wait: 1000
    },

All .js files are loaded with path
But templateUrl is loaded with path
How can I configure to load templateUrl with path similar to .js file ?

Answer №1

Due to the length of this response, I have posted it as an answer instead of a comment.

In response to your question, you must provide a path from the src folder, which is currently working post my earlier comment. Additionally, you mentioned about .map files.

It is possible to configure automatic mapping paths when loading templateUrls by creating gulp tasks like so:

Add this code to your gulpfile.js:

gulp.task('compile-ts', function () {
    var sourceTsFiles = [
        config.allTs,
        config.allcompoTs
    ];

    var tsResult = gulp
        .src(sourceTsFiles)
        .pipe(sourcemaps.init())
        .pipe(tsc(tsProject));

    return tsResult.js
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(config.tsOutputPath));
});

And include this in your gulp.config.js:

module.exports = function() {

    var config = {
        allTs : 'src/*.ts',
        allcompoTs: 'src/**/*.ts',
        tsOutputPath : 'dist/',
        index : 'index.html'
    };
    return config;
};

You can now customize gulp tasks according to your needs. I hope this proves helpful!

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

Media publications do not conform to the current trends

I'm currently utilizing the HTML-to-paper plugin to print my content on a printer. However, I've encountered an issue where it doesn't seem to apply any of the styles I've defined within @media print. The challenges I'm encounteri ...

react-intersection-observer is specifically designed to function with the final elements

I am currently working on implementing the Lazy Loading feature using react-intersection-observer. The main objective is to load images in the boxes only when they appear within the viewport. At the moment, as I scroll down to the last elements, all the i ...

Display a loading component within the navbar in React while waiting for data to be retrieved

I recently updated my navbar component to accept dynamic values for menu titles. One of these dynamic values is the username, which needs to be fetched asynchronously. To handle this, I decided to display a loading animation until the username is fully fet ...

Get the specific URL path from the designated <input type="file"> location

I recently encountered an issue with retrieving the file path of a selected file. I used the normal file type and attempted to use the .val() function, but it only returned the file name and not the full location of where the file is stored on my local mac ...

What is the best way for Laravel to utilize the information provided via an Angular Ajax post request

Hi there, I'm currently working on my Angular app and I am attempting to send some data over to Laravel. $scope.add = function(){ if($scope.new_brand.trim() !=='') $scope.brands.push({name:$scope.new_brand}); $http.post('brand ...

The hyperlink to a different webpage does not trigger any JavaScript functionalities or render any CSS styles

I am facing an issue with linking HTML pages that run Javascript and JQuery Mobile from another HTML page. My link setup is as follows: <a href="hours.html">Hours</a> The linking page and the linked pages are in the same directory. However, ...

Provide arguments for Auth0 registration

Incorporating Auth0's provided login and sign-up screen (check it out at https://auth0.com/docs/quickstart/webapp/nextjs/01-login#add-login-to-your-application) into my application has been a seamless process. Upon signup, I have implemented a callbac ...

Creating a CSS animation to slide a div outside of its container is

I currently have a flexbox set up with two adjacent divs labeled as DIV 1 and DIV 2. By default, both DIV 1 and DIV 2 are visible. DIV 2 has a fixed width, occupying around 40% of the container's width. DIV 1 dynamically adjusts its width to ac ...

Dropdown box not displaying any choices

I developed a basic reusable component in the following way: Typescript (TS) import {Component, Input, OnInit} from '@angular/core'; import {FormControl} from '@angular/forms'; @Component({ selector: 'app-select', templa ...

Executing asynchronous JavaScript calls within a loop

I've encountered an issue with asynchronous calls in JavaScript where the function is receiving unexpected values. Take a look at the following pseudo code: i=0; while(i<10){ var obj= {something, i}; getcontent(obj); / ...

JavaScript: Array methods and Functions

export function getPlanetNames(data) { const pNames = data.planets; const results = pNames.filter(function (getNames) { return getNames.name; }); return results; 'data' is stored in a separate file and consists of an object array wit ...

Updating the state on a click event triggered by a MenuItem in React using Material UI

I'm currently working on implementing state changes based on dropdown selections using Material UI. However, I've encountered an issue where the code snippet below (simplified) only returns the list item, and I'm unsure what steps to take n ...

I am puzzled by the Policy Violation notification I received, especially since I have been in compliance with API Level 33 regulations since August 25, 202

Hey there! I'm wondering why Google Play Console has flagged me for violating policy on API Level 33. This issue started on August 25, 2023 with version 7.0.4 currently in production. I made changes to the config XML file. Just so you know, this was ...

What causes the transformation of [{"value":"tag1"} into [object Object] when it is logged?

Currently on my node.js server, the code I'm using is as follows: var tags = [{"value":"tag1"},{"value":"tag2"}]; console.log("tags: " + tags); My expectation was to see this in the console: tags: [{"value":"tag1"},{"value":"tag2"}] However, what ...

Utilizing Jest and nest.js for testing with absolute paths

Looking at my jest configuration inside the package.json: "jest": { "moduleFileExtensions": [ "js", "json", "ts" ], "moduleDirectories":["node_modules", "src" ...

Is there a way to modify the starting position of my shapes in Three.js?

Is there a way to adjust the starting position of my geometry? Currently, it appears in the center of the canvas, but I would prefer it to be at the top left corner. Any suggestions on how to achieve this? scene = new THREE.Scene(); camera = new THRE ...

As you scroll, a box blocks off half of the screen

Hey everyone, I could really use your assistance! I'm working on developing a javascript code and here is the idea - if anyone can contribute to it. It's like a social media platform where users enter the site and the is_user_logged_in parameter ...

Leveraging jQuery's `.eq()` method on multiple class selectors

Is there a way to effectively utilize the 'eq' function on multiple classes? Due to the non-sequential nature of the divs with class 'a', I am encountering difficulties with using the 'eq' function to update their class. Inter ...

Adding information into MongoDb with the help of mongoose

I am currently working with an array of strings and my goal is to iterate through this array and update my collection with its values. This is the approach I have taken: if (employees) { employees.map((employee) => { Employee.updateOne({ ...

Leverage the Power of Two AngularJS Factories

Can I efficiently use two Factories in AngularJS by calling one from the other? Here's the Scenario: I have a Factory that returns an Array. This Factory is responsible for checking if the data to populate this Array already exists in local SQL Stor ...