Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Angular Enterprise Development-Angular MVC implementation

Shulou Source: shulou.com Published: 2022-06-01 03:00:20 09月24日 Update

1.MVC introduction

Model-View-Controller

A software architecture invented for the programming language Smalltalk in the 1980s. The purpose of MVC mode is to realize a dynamic programming, simplify the subsequent modification and expansion of the program, and make it possible to reuse a certain part of the program. In addition, this mode makes the program structure more intuitive by simplifying the complexity. The software system not only separates the basic parts of itself, but also gives each basic part its due function. Professionals can be grouped by their own expertise:

Controller (Controller)-is responsible for forwarding requests and processing them.

View (View)-the interface designer designs the graphical interface.

Model (Model)-the functions that programmers should have in writing programs (implementing algorithms, etc.), database experts for data management and database design (which can achieve specific functions).

2.Angular MVC

In AngularJS application, MVC design pattern is realized by JavaScript and HTML. HTML is used to define views, and JavaScript is used to implement models and controllers.

Views in 2.1Angular MVC

In AngularJS applications, views are created using HTML, and the HTML can be a simple, separate page or a html code snippet.

A simple HTML page:

Hack Hands Angular-DemosHello World

AngularJS applications are mostly SPA (Single Page Application) applications, the current page only shows part of the content of the application, through ng-view to load more view content. The html file containing ng-view is as follows:

Controllers in Hack Hands Angular-DemosHack Hands Angular DemosHello World2.2 Angular MVC

The controller of the application, which is essentially a function of JavaScript, is used to connect the page template with the logic code, and to enhance the scope of the template by adding objects and behavior. in AngularJS, it can be specified by using the ng-controller instruction on the tag or in the route when ui-view is configured.

/ / Code goes herevar hackApp = angular.module ("hackApp", []); var indexController = hackApp.controller ("indexController", function ($scope) {/ / controller logic goes here $scope.message = "Hello Hacking World"}); Models in 2.3 Angular MVC

Model belongs to the data layer, which can represent either the data model object of the entire Anglar application or only an entity object.

The Model data model object is attached to the scope, and either the whole model object or an entity object must be referenced by the scope of the Angular as an attribute, which can be created explicitly or implicitly.

Tags: Programs applications objects data models designs functions views pages roles controllers patterns controls people code content entities databases templates interfaces Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei MariaDB Apple macOS