Paul
Paul

Reputation: 301

Use Angular 2 in a multiple page website

How do you get from the Angular 2 quickstart app to using Angular 2 in a website?

My main problem is that the index.html in not in the route folder of the app. Also is it possible to have many pages that have angular 2 apps?

I realise that Angular 2 is designed for SPAs but the html component system must be useful in all sorts of websites.

Good page here Is AngularJS just for single-page applications (SPAs)? but no actual info on how to do it.

I would like to use a much or as little angular 2 as necessary in different pages across my website project.

A sample website using angular 2 in this way would be great.

Upvotes: 3

Views: 3574

Answers (1)

Paul
Paul

Reputation: 301

To answer my question (just in case anyone is interested), I just use a little TypeScript to load my html templates. Simple.

public static getFileContentAsync = async (path: string): Promise<string> =>
{                 
    return await new Promise<string>((resolve, reject) => 
    {                                    
        // Set up the xml http request object.
        let xhr: XMLHttpRequest = new XMLHttpRequest();
        xhr.open("GET", baseUrl + path);
        xhr.send();

        xhr.onload = () => 
        {                               
            resolve(xhr.response);
        };

        xhr.onerror = (errorEvent: ErrorEvent) =>
        {
            reject(errorEvent);
        };
    });
} 

Upvotes: 1

Related Questions