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