gpt4 book ai didi

angularjs - Controller 替换为 Component angular 2

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

我不太容易区分 ComponentControllerController 如何替换为 angular 2 中的组件? 我读到有关组件的信息:

In Angular, a Component is a special kind of directive that uses a simpler configuration which is suitable for a component-based application structure.

This makes it easier to write an app in a way that's similar to using Web Components or using Angular 2's style of application architecture.

Advantages of Components:

  • simpler configuration than plain directives
  • promote sane defaults and best practices
  • optimized for component-based architecture
  • writing component directives will make it easier to upgrade to Angular 2

When not to use Components:

  • for directives that need to perform actions in compile and pre-link functions, because they aren't available
  • when you need advanced directive definition options like priority, terminal, multi-element
  • when you want a directive that is triggered by an attribute or CSS class, rather than an element.

来自 AngularJs Documentation

还有,读取Directive vs Component之间的区别

但我在 component 中实现了与我们在 controller 中相同的 logic

有人可以解释一下吗?以及如何从 controllercomponent Angular 考虑应用程序的架构。

最佳答案

如您所问,我不会从应用程序架构的 Angular 来区分它们。这几乎是相同的概念,只是重新命名并变得更容易。长话短说,您可以将其视为同一类型的实体。

我认为 componentcontroller 更容易被人们掌握,尽管它适合 MVC,是最后一个“C”。通常将组件作为 UI 的元素进行推理会更容易一些。人们可以认为整个 UI 由多个组件组成,每个组件都在创建整个画面,因此从 Angular 团队的 Angular 来看,这个名字更合适。我也更喜欢组件。

关于angularjs - Controller 替换为 Component angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41649382/

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