gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 19:29:35 25 4
gpt4 key购买 nike

如何从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com