Pairing Angular2 with the power of Turbolinks

Currently, I am utilizing async script loading with SystemJS for jQuery, Angular2, and other scripts. My goal now is to integrate Turbolinks into this setup. Despite everything functioning correctly, I am encountering an issue where my Angular component only renders the first time. When navigating to the next page using Turbolinks, the component fails to render. Interestingly, there are no errors visible in the object inspector, and the source code only displays:

<search-app></search-app>

I have attempted to debug in the object inspector, but after progressing to the second page, only the HTML tag remains.

Below are the scripts being loaded via SystemJS in the Head tag of my page:

System.config({

            meta: {
                '/bundles/frontall': { format: 'global' },
                '/bundles/raphael': { format: 'global' },
                '/bundles/zopim': { format: 'global' },
                '/bundles/angular2': { format: 'global' }
            },

            packages: {
                'angular': {
                    format: 'register',
                    defaultExtension: 'js'
                },

                'angular2': {
                    format: 'global',
                    defaultExtension: 'js'
                },

                'rxjs': {
                    format: 'global',
                    defaultExtension: 'js'
                }
            },

            paths: {
                'angular2/*': 'scripts/angular2/*',
                'rxjs/*': 'scripts/rxjs/*'
            }
        });


         System.import('/bundles/frontall').then(function () {
            Promise.all([
                System.import('/bundles/zopim'),
                System.import('/bundles/raphael'),
                System.import('bundles/angular2'),
                @RenderSection("asyncScripts", required: false)
            ]).then(function () {

            System.import('angular/searchApp');
        });

Within the frontAll bundle lies the file site.js, where all components are re-initialized:

function componentInit() {

//init material design
$.material.init();

//init texarea autosize
autosize($('textarea'));

//init parallax
$('.parallax-window').parallax();

//init smooth scroll
//SmoothScroll();

//init css3 animate it
$.animateIt();
$.doTimeout();
$.animateItInit();

$.srSmoothscroll({
    step: 80,
    speed: 90,
    ease: 'linear',
    target: $('body'),
    container: $(window)
});  
}

$(function () {
    componentInit();

});

$(document).on('page:load', function () {
    componentInit();
});

The Angular 2 version being used is beta 7. Can anyone pinpoint the cause of this issue? Thank you!

Answer №1

This code snippet is essential for integrating into my angular2 application successfully:

jQuery(function () { 
    bootstrap(searchApp, [ElementRef, TournamentSearchService]); 
}); 
jQuery(document).on('page:load', function () { 
    bootstrap(searchApp, [ElementRef, TournamentSearchService]); 
}); 

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

eliminate the gap in the MUI Accordion when it is expanded

How can I prevent the Accordion MUI component from moving and applying top and bottom margins to summary elements in expanded mode? I added the following code to the summary element but it doesn't seem to be working. Any suggestions on how to fix this ...

Presenting a trio of distinct tables each accompanied by its own unique button option

I am attempting to create a functionality where there are 3 buttons and when a user clicks on one of them, it shows the corresponding table while hiding the other two. I have experimented with using getElementById to manipulate the display property of the ...

Utilize a specified router outlet for loading a module lazily or for child modules

I am working on a project where I need to load pages with a configuration bar at the top. Each page will have a unique configuration setup that is specific to that page. In my app.component.html file, I have defined the following: <router-outlet name= ...

I am having trouble getting debugging with source maps to work in VSCode and Browserify

I'm currently experiencing an issue with setting breakpoints in Chrome using VSCode, especially when working with TypeScript and Browserify. Oddly enough, if I open Chrome separately and manually refresh the page, the source maps load correctly and I ...

When clearInterval is used to stop a setInterval, it will not automatically restart if reset with setInterval

I am facing an issue with a countdown timer that I have created using setInterval in JavaScript. The timer is supposed to countdown from one minute at one second intervals. However, when I click the "start" button, it starts the countdown but if I click an ...

The automatic filtering feature does not kick in when the sorting is changed

I've been working on an app that features a video database, allowing users to filter videos by category and sort them by rating. https://i.sstatic.net/cESZT.png Currently, the filtering system works fine once the options are changed. However, there ...

The content of the message will be outside of the main container

Development Environment ・ react ・ typescript ・ styled-components To display messages, the map function is utilized. In case of long text, it may extend beyond the parent element. It is desired to have the text wrap around the parent when ex ...

Encountering the error message "Uncaught TypeError: $.ajax is undefined"

Recently, I encountered an issue with my form that utilizes ajax to send user information to a php file. The form is embedded within a bootstrap modal and was functioning perfectly until I attempted to add an extra field for enhanced functionality. However ...

"Learn how to update an existing table row and populate its cells with JSON data retrieved from a successful AJAX request without creating a

Currently, I am utilizing CouchCMS. The platform offers a feature known as repeatable regions which essentially generates tables to showcase recurring content. The defined repeatable region looks like this: <cms:repeatable name="item_detail" ...

The development server fails to respond when initializing a new project following the NextJs documentation for an empty project

After consulting the NextJs framework documentation, I meticulously followed the setup instructions to initialize an empty project : mkdir hello-next cd hello-next npm init -y npm install --save react react-dom next mkdir pages Subsequently, I included t ...

Using the @ Symbol in Javascript ES6 Module Imports

One of the folders in my node_modules directory is called @mymodule, and within it, there is another folder named 'insidefolder'. The path to this folder looks like this: node_modules/@mymodule/insidefolder When trying to import insidefolder us ...

File Upload yields a result of 'undefined'

Currently, I am utilizing Express File Upload. When attempting to send a post request to it, the error-handler returns an error indicating that no files were found. Upon logging console.log(req.files), it shows as undefined, causing the error to be sent ba ...

Using a file readStream within a post handler with Node.js, Request, and Express

Currently, I am utilizing nodejs and express4 for my development tasks. I am facing an issue with a form that has a post method for uploading files as base64, which I am then saving to a gridfs using streams. Below is the code snippet I am working with: ...

How to incorporate paginating in MongoDB operations

It's a well-known fact that using skip for pagination can lead to performance issues, especially as the data set grows larger. One workaround is to leverage natural ordering using the _id field: //Page 1 db.users.find().limit(pageSize); //Get the id ...

Error message: The import from './components/headerComponent/header' failed because it does not have a default export. Make sure to export it as default to be able to import it

I've been trying to bring a header from one file into another, but it's not cooperating. import React from 'react'; import { Typography, Card, CardContent } from '@material-ui/core'; import Header from './components/head ...

What is the most effective way to programatically display a graphic component (.ts files)?

Currently, I am working on a web application project using Angular 6. In this project, a graphic component is essentially an HTML template paired with logic stored in a .ts file. I have encountered a scenario where, in another typescript file associated w ...

Tips on updating the date format of Vuetify's calendar

I am currently working on implementing inputted events into the Vuetify calendar provided in this link: https://github.com/vuetifyjs/vuetify/blob/master/packages/docs/src/examples/calendars/complex/events.vue. The issue I'm facing is that when I try ...

Acquire the "value" and utilize it within a different function

I am facing a minor issue with my JavaScript code. I have been working on creating a gallery page. In this page, there is an icon that triggers a function called "comment" when clicked. function comment() { var div = document.getElementById("commentdiv") ...

Utilize the Material UI SelectField component as a reference for handling onChange events

I'm facing a challenge with my form that contains over 15 SelectField components. I want to avoid creating multiple change handler functions, but I can't figure out how to identify the specific select field that triggered the change event in orde ...

Guide on extracting matching values from one object based on the properties of another object

Looking to iterate through the object below and extract author names based on matching titles with other objects. The goal is to create a new object for easier management. business1 { "type": "FeatureCollection", "features": [ { ...