简体   繁体   English

使用普通/vanilla JavaScript 的 Angular 2 组件

[英]Angular 2 component using plain/vanilla JavaScript

Due to some architectural decisions, my team has decided to fallback to using Javascript without any framework dependencies (Angular or react).由于一些架构决策,我的团队决定回退到使用没有任何框架依赖(Angular 或 react)的 Javascript。

I would now want to write custom components(that do the exact same thing as Angular's components: a selector that can be used in HTML with a scope & a controller to play with) with no dependencies on frameworks.我现在想要编写自定义组件(与 Angular 的组件做完全相同的事情:一个可以在 HTML 中使用的具有范围和控制器的选择器)而不依赖于框架。

jQuery widgets is an option we thought of. jQuery 小部件是我们想到的一个选项。 But there's a dependency on jQuery :(但是对 jQuery 有依赖性 :(

What's the best approach to proceed?继续进行的最佳方法是什么? Does ES6 provide any ways to do this? ES6 是否提供了任何方法来做到这一点?

Angular is parsing the html and searching to match with the selectors.. before this, it parses your templates to generate dynamic code... and a lot more things under the hood.. so, no, you wont be able to create a custom html tag easily. Angular 正在解析 html 并搜索以与选择器匹配......在此之前,它会解析您的模板以生成动态代码......以及更多幕后的东西......所以,不,您将无法创建自定义html标签很容易。 Maybe take a look at Polymer?也许看看聚合物? https://www.polymer-project.org/ https://www.polymer-project.org/

Why bother creating something what is sucessfully done by a huge team of developers on your own?为什么要费心去创造一些由你自己的庞大开发团队成功完成的东西? You will most likely fail.你很可能会失败。

But if you still want to try it, there's a thing called WebComponents , but it has very limited browser support at the moment.但是,如果您仍然想尝试一下,有一种叫做WebComponents的东西,但目前它对浏览器的支持非常有限。 A better support would also lead to another library called Polymer .更好的支持也会导致另一个名为Polymer 的库。

Another lightweight library to create custom components is Vue.js .另一个用于创建自定义组件的轻量级库是Vue.js。

Fyi: React isn't a framework.仅供参考: React不是框架。

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

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