On the chaos of angular

Source: Internet
Author: User

About angular, has always been a kind of foggy feeling, I think many developers, especially after the end of the programmer, for the scope controller service in angular has a lot of special feelings, it is a word chaos

The community has given a lot of suggestions about angular's best practices, but I personally feel that the proposals themselves point to some of the conceptual ambiguities that JavaScript itself is a language of great flexibility, as a framework for architecture, A little unclear will lead to a lot of obvious problems.

What is 1.scope modal?state?viewmodal?

Scope This word is literally the scope, is a controller under the object, from this layer of relationship, it should not be counted modal, because parasitic on the controller, is a strong coupling between the relationship, However, in many examples of angular, this is written directly scope.name = ' Jacky ', so there is a simple binding, rapid display, initially this is to highlight the angular as an automated framework of the powerful, and then led to a large number of developers as a modal, Or Viewmodal, in the MVVM mode Viewmodal is the controller exists, obviously simple scope can not afford this task, must add controller but controller is a separate part, then it seems Scope is not considered a viewmodal, so what is scope exactly?

From another point of view, angular in addition to the Controller service also designed directive, Directive's configuration also contains the controller scope, but here the scope The directive is bound to a property, function, expression on the, in fact, we do not pre-set a scope = Xxxmodal To configure instructions and angular not allow this configuration, then from this design scope is actually a UI component of the State, So the problem is, in a bunch of seemingly classic controllers, scope plays a variety of roles, and the hidden behind is actually a state, which clearly creates confusion. There is no clear definition of the use of scope, Directive, in fact, can only be packaged inside the project.

What exactly is 2.controller? control?viewcontrol?action?

In. NET MVC, control is an upper-level manager of action, and each route specifies not only the control but also the action, so that in the definition, different operations under the same large page are lumped together, and the structure of the project is more reasonable. And take a look at angular,angular. The definition of control is more like an action from the route setting, and we can specify control for each UI component, as small as a button to a whole page, which leads to a problem That is, as the project progresses, a lot of control estimates can not be avoided, some people will say that there are module, I have to say that the angular module is a namespace, and not so good. Because of the JavaScript loading mechanism, We have to specify a module for each file, which is part of the angular best practice, so how many control means there are more than one module, of course, more, not less.

If control is action, it is from the route, but from a view point of view, every directive can have its own control apparently a directive includes a variety of user interactions naturally cannot have only one action, From a react perspective, the control in the encapsulated UI component should be a series of interactive schedulers, at least directive this part of angular, and control is a viewcontrol.

From a data point of view, the community's best practices give advice that each view should have a separate service as part of the data capture, or even modal meaning, then control is a real control, It's responsible for crawling the data and binding it to the view, which seems pretty good, but before that, everyone is writing HTTP requests directly in the control, which is obviously another mess. So control is what, look at the mood, play it yourself.

What exactly is 3.service? modal? tool functions?

There are many ways to define service in angular there are factory,provide, and the service itself, this is a mess, from the definition of the way we can almost see, Xxxservice->xxxfactory, Xxxservice-Xxxprovide, xxxservice-> Xxxservice, do not understand AH completely do not understand, service defined service also forget, the remaining factory and provide in the end is a very!

Service call services, from the initial design of angular, I think is defined as HTTP encapsulation, however with the continuous development of angular, service becomes more and more large and bloated, and chaotic, because of the characteristics of dependency injection, Angular is not advocating for the management of namespaces, so we have a variety of third-party services, tool functions, and so on are sealed into service, and in fact, in these service also rely on other service, this definition of ambiguity and dependence of confusion, Has brought a lot of trouble to the late stages of the project.

In fact angular as a perfect self-formed framework, from the birth to now has been carrying too much, which also led to the framework of the original design and actual development of the uncoordinated, this uncoordinated and as the needs of developers become larger, if the framework itself has a chaotic nature, For the project is also really a kind of a problem.

On the chaos of angular

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.