简体   繁体   English

使用Angular2将UI添加到现有站点

[英]Using Angular2 to add UI to an existing site

By adding data- attributes to the markup of an existing site I can embed the metadata required to write client-side code to add features to the existing pages, eg, bring up a detail or editor box, or show related info. 通过将data-属性添加到现有站点的标记,我可以嵌入编写客户端代码所需的元数据,以向现有页面添加功能,例如,调出详细信息或编辑框,或显示相关信息。

It seems straightforward enough to approach this using jQuery with KnockoutJS and Bootstrap for a responsive and good looking UI. 使用带有KnockoutJS和Bootstrap的jQuery来实现这一点似乎很简单,以获得响应性和美观的UI。

Could I use Angular? 我可以使用Angular吗? What I don't understand is that in all the Angular2 examples the whole site is an Angular2 SPA whereas I want to add some new UI components to an existing site. 我不明白的是,在所有Angular2示例中,整个站点都是Angular2 SPA,而我想在现有站点中添加一些新的UI组件。

If I could use Angular then how would I approach it? 如果我可以使用Angular那么我将如何处理它? How would the Angular components get bootstrapped in the page? 如何在页面中引导Angular组件?

You can definitely use Angular in web app that use other JavaScript frameworks or library. 您绝对可以在使用其他JavaScript框架或库的Web应用程序中使用Angular。 Usually when you do that you use Angular as the main framework. 通常,当您这样做时,您使用Angular作为主框架。 In Angular 2 your Angular app start with a root component so if you insert the root component to some div in your html page the Angular system will not be aware of things outside of the root component (you can achieve that with workarounds but this is not a good practice). 在Angular 2中,你的Angular应用程序以root组件开头,所以如果你将根组件插入到html页面中的某个div,Angular系统将不会知道根组件之外的东西(你可以通过变通方法实现这一点,但这不是一个好的做法)。

If you want to transform something to Angular you can put all of the html code inside the root component and then slowly transform it to the Angular way (Angular components). 如果要将某些内容转换为Angular,可以将所有html代码放在根组件中,然后慢慢将其转换为Angular方式(Angular组件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM