Angular组件通信与框架演进

5星 · 超过95%的资源 需积分: 9 61 下载量 78 浏览量 更新于2024-07-19 2 收藏 6.64MB PDF 举报
"Angular in Action-Manning(2018).pdf" 本书深入探讨了Angular框架,这是一个在Web开发领域有着深远影响的重要框架。AngularJS(1.x版本)曾是其时代最受欢迎的Web应用程序框架之一,它推动了多项重要概念和技术的普及。然而,1.x版本存在局限性,尤其是在大型应用中,早期被大力宣传的双向数据绑定功能成为了性能瓶颈。为解决这个问题,Angular引入了一次性和一次性绑定选项以提高性能,但需要开发者主动选择使用。组件的引入是为了更好地组织和构建应用程序,但利用它们则需要对现有应用进行重构。 尽管可以使用AngularJS 1.x构建出色且高性能的应用,但这并不是默认模式,需要开发者放弃一些早期被认为的最佳实践。随着经验的积累,Angular团队决定从头重写框架,将学到的教训融入下一代主要版本的基础中。这个多年的努力涉及到了Google的Angular团队和早期采用者社区,最终诞生了Angular 2.0及其后续版本。Angular 2.0自发布以来,社区迅速发展壮大。 本书在Angular 2.0早期beta阶段就开始编写,而那时Angular正处于快速迭代之中。如今,Angular已经稳定,并遵循明确的发布周期进行新特性和弃用功能的更新。书中的示例适用于Angular 5及以上版本,并且GitHub项目会提供关于如何跟上Angular演进的任何必要更改的注释。 书中特别提到了Angular组件之间的通信。Angular应用基于组件,组件之间通过输入和事件进行通信。就像HTML元素的行为一样,父组件通过输入绑定将数据传递给子组件,这是Angular实现从父组件到子组件数据共享的方式。此外,Angular还会跟踪数据变化,知道何时需要重新绘制屏幕。例如,在第5章所示的应用结构中,Dashboard组件包含数据,并使用输入绑定将数据传递给两个Metric组件和两个Nodes组件。当数据发生变化时,Angular会自动更新视图。 在组件通信的过程中,Angular提供了多种机制,如事件发射(@Output)和输入属性(@Input)。事件发射允许子组件向父组件发送消息,而输入属性则用于从父组件向子组件传递数据。此外,Angular还支持服务(Services)来在不同组件间共享状态和服务,以及依赖注入(Dependency Injection)来简化组件间的数据传递和依赖管理。 这本书详细介绍了Angular的演变、核心概念和实际应用,包括组件通信、数据绑定、性能优化和框架的最新发展,是学习和掌握Angular不可或缺的参考资料。
2019-09-06 上传
Summary Web Components are a standardized way to build reusable custom elements for web pages and applications using HTML, CSS, and JavaScript. A Web Component is well-encapsulated, keeping its internal structure separate from other page elements so they don't collide with the rest of your code. In Web Components in Action you'll learn to design, build, and deploy reusable Web Components from scratch. Foreword by Gray Norton. Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology The right UI can set your sites and web applications apart from the ordinary. Using the Web Components API, you can build Custom Elements and then add them to your pages with just a simple HTML tag. This standards-based design approach gives you complete control over the style and behavior of your components and makes them radically easier to build, share, and reuse between projects. About the Book Web Components in Action teaches you to build and use Web Components from the ground up. You'll start with simple components and component-based applications, using JavaScript, HTML, and CSS. Then, you'll customize them and apply best design practices to maximize reusability. Through hands-on projects, you'll learn to build production-ready Web Components for any project, including color pickers, advanced applications using 3D models, mixed reality, and machine learning. What's inside Creating reusable Custom Elements without a framework Using the Shadow DOM for ultimate component encapsulation Leveraging newer JS features to organize and reuse code Fallback strategies for using Web Components on older browsers About the Reader Written for web developers experienced with HTML, CSS, and JavaScript. About the Author Ben Farrell is a Senior Experience Developer at Adobe working on the Adobe Design Prototyping Team.