What happend about Angular2.0

前几天听到朋友说,可以不用看angular了,angular2.0的改动是颠覆性的,出于好奇看了angular2.0的视频介绍。

Angular 2.0 Core
Angular 2.0 Core by Igor Minar & Tobias Bosch

首先我们来看看Angular1和Angular2在语法上的区别:

AngularJS-1.3 AngularJS-2.0

可以看到原来的ng-controller、ng-model、ng-click等关键词都替换成了使用括号的属性。右边则是表达式。视频里讲到了Properties & Attributes的区别,之前我一直分不清这两这到底有什么区别,现在算是明白了,引用原话解释:

All elements have properties and some properties are serializable into attributes and those that are always restricted(受限制的) to using just a string type.
So we find properties to be more flexible because they have different types and usually the API surface is bigger.

为什么说angular的改变是颠覆性的,来看看下面几张图,相信看完后你会吐血

controllers killed

DOO killed

$scope killed

angular.module killed

这几张图形象地表示Angular2.0中controller被删掉了,DDO被删掉了,$scope被删掉了,module被删掉了……,变成和React的一样的Components Based了,也就意味着MVC的时代也即将成为过去。

In Angular 1,we started with templates and controllers and the component model was actually an afterthought.

In Angular 2,we’re embracing(拥抱) the component model and we’re making components the basic building component directive.

Directives and DI
summary

可见组件化开发是一种趋势,去年我开始接触了Web Components,Web Components 核心是自定义标签,而我学习的对象是Facebook的Reactjs。

关于Web Components规范

https://w3c.github.io/webcomponents/explainer/
http://www.polymer-project.org/docs/start/creatingelements.html

1 Comment

发表评论

电子邮件地址不会被公开。 必填项已用*标注