Project preparation and environment building operations in Angular4

巴扎黑
Release: 2017-08-07 15:50:36
Original
1779 people have browsed it

This article mainly introduces the preparation of Angular4 study notes and the environment construction project, which has certain reference value. Interested friends can refer to

The nonsense written in front 1

When I used Angular, it was still version 1. I am an engineer who switched from j2ee to Android, which means that my daily development language is Java. It was really uncomfortable to suddenly switch to JavaScript, like a polar bear talking to a penguin, not to mention that later I felt that webstorm was too laggy and I used sublime without prompts (well, I finally cured the "never remembering function names syndrome" that had been a problem for many years). After a painful experience of hitting the wall, I finally started to get used to it.

But I still want to yell, JavaScriptWCNM.

After venting, let’s get down to business.

The main front-end framework now is React. Although Angular is backed by Google, it is still a little behind. I have used both. Let me talk about the characteristics of Angular and the differences between it and React.

First of all, it is unfair to compare Angular and React directly. Because Angular is a family bucket that has everything, React is just the V in MVC, and it often needs to be used with other things such as redux (the standard configuration I use is react+redux+router). .

Secondly, Angular is characterized by binding, which is more in line with the concept of MVC from the perspective of writing code. The component in 4.0 is equivalent to the combination of C and V, template or templateUrl is the view, and class is the so-called controller. By declaring the only Model in the Controller to be used in the corresponding View, the purpose of decoupling is achieved. Moreover, Angular also supports injecting services to further separate business logic.

The characteristic of React is actually virtual dom, which is a speed-up thing. Redux is logically related and decoupled through a unique state. You change the state and I change the value. The ideas of both are very similar. Personally, I feel that the reducer in Redux is the service in Angular.

Third, which one is better? Personally, I still like React more. Of course, this subjective factor plays a large role. When I was writing Angular, I was still a resentful Android programmer, and when I was writing React, I was already an entry-level front-end developer.

Nonsense written in front 2

Some preparation work is necessary.

node, the basis of everything.

sublime, this is the IDE I use personally. I have used webstorm before, but it requires registration and is somewhat slow. However, the small disadvantage of using sublime is that you need to download the plug-in yourself. Webstorm is indeed more versatile... Subime's support for React is quite good, but its support for Angular is still a bit awkward. Of course, it's also possible that I didn't install the correct plug-in.

git, this project has been submitted to github. Of course, the level of updating is inversely proportional to my level of laziness. In fact, I have already completed this project, but it was deleted due to some mysterious power from the East (let’s be honest, I’m just cheap)...

Good English, not required. But if you are good at English, you can go directly to the official website of Angular, the portal, it will be faster if you can bypass the wall. The Chinese version of Angular is still stuck at 2.0, and the writing method is slightly different from 4.0.

Of course there is not much difference between 4.0 and 2.0, at least it is much smaller than the difference between 2.0 and 1. There are 2 but not 3 because I feel that most of the time I only need to commit two.

Let’s talk about demand first - any project without demand is just a joke! flow! Hooligan!

The requirements are very simple, and it basically imitates the preparation page of Super Robot Wars (yes, I am a Gundam fan and I happen to be playing Robot Wars Z recently).

First of all, this project contains 3 pages:

1 Home page


Project preparation and environment building operations in Angular4
The upper part shows the project Description, the lower half selects 3 bodies and gives a brief explanation.

2 Aircraft list page


Project preparation and environment building operations in Angular4# Aircraft display, showing all owned airframes, including name and status (in order to prevent Project preparation and environment building operations in Angular4 infringement, use It’s a Gunpla that I made myself).

3 Body details page


Project preparation and environment building operations in Angular4Click on any body from the homepage and details page to jump to this page, which mainly introduces the body Various parameters, basic situation and status.

Environment setup

First you need node and sublime, and then you need to use sublime's package manager to install the plug-in typescript.

For how to install node and sublime package managers and download plug-ins, please refer to the methods in previous articles.

Secondly, you can use sourceTree or the command line to clone the address:

1) The official quickstart given by angular

##
https://github.com/angular/quickstart.git
Copy after login

2) Mine The advantage of the adapted version is that it integrates webpack and scss. The disadvantage is that the writing is messy and I don’t know what the pitfalls are.

https://github.com/stormrabbit/gundam-meister.git
Copy after login

Third, npm install installs various dependencies.

If the installation fails, you can consider using cnpm

cnpm:


npm install -g cnpm --registry=http://r.cnpmjs.org npm install microtime --registry=http://r.cnpmjs.org --disturl=http://dist.cnpmjs.org
Copy after login

假装安装一下

Project preparation and environment building operations in Angular4

运行命令 npm start

Project preparation and environment building operations in Angular4

目录结构:

Project preparation and environment building operations in Angular4

src/main.ts 项目的入口文件 暂时不需要修改

src/index.html 项目展示的html,容器,相当于java的虚拟机,标签是自定义的component的标签化。

src/app/app.module.ts 项目的配置文件,所用的component、注册的service以及以后会有的routing等等都会注册到这里。相当于Android的mainfist.xml文件。

src/app/component/appcomponent/app.component.ts 项目的第一个容器,也是项目的正式入口。相当于java中的main函数,Android中的MainActivity。当然也不是一定要叫这个名字,不过是一种约定俗成。其中template是html页面,相当于view,class相当于controller。

访问http://localhost:3000/,显示页面

Project preparation and environment building operations in Angular4

环境搭建完毕,hello,world。

The above is the detailed content of Project preparation and environment building operations in Angular4. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!