angular - 在多页面网站中使用 Angular 2

标签 angular

如何从 Angular 2 快速入门应用到在网站中使用 Angular 2?

我的主要问题是 index.html 不在应用程序的路由文件夹中。还有可能有许多页面有 Angular 2 应用程序吗?

我意识到 Angular 2 是为 SPA 设计的,但 html 组件系统必须在各种网站中都有用。

好的页面在这里Is AngularJS just for single-page applications (SPAs)?但没有关于如何操作的实际信息。

我想在我的网站项目的不同页面中根据需要使用或多或少的 angular 2。

以这种方式使用 angular 2 的示例网站会很棒。

最佳答案

为了回答我的问题(以防万一有人感兴趣),我只使用了一点 TypeScript 来加载我的 html 模板。简单。

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);
        };
    });
} 

关于angular - 在多页面网站中使用 Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43067866/

相关文章:

Angular:文本搜索 rxjs 问题

Angular 4 获取用 *ngIf 隐藏的元素的高度

angular - 来自 Angular 4 的 HttpInterceptor 单元测试

javascript - 我想在 Angular 6 中更改页面内容而不重新加载

forms - 如果兄弟组件中的表单无效,则禁用另一个组件的按钮

node.js - Angular6同步加载路线数据

angular - RxJS - 如果输入可观察对象为空数组,则 switchMap 不会发出值

angular - 如何在 Angular 中处理表单错误验证

html - 如何使用 Angular Material 创建粘性 header ?

css - Angular 2 中的组件背景颜色