Angular2相对于Vue的优势在Vue2.0之后已经削弱很多了。比如SSR(Vue2已经原生支持)和全栈式框架(官方推荐Vuex+Vue-Router),native端也有阿里巴巴的weex。
但是Angular2在API设计的完整度和覆盖度上还是Vue所不能及的,主要有这么几点
1. Angular2原生Form支持:
Angular2原生的Form模块功能相当强大。除了双向绑定之类的基本功能,还能通过programatic API 控制dom元素的表单行为。也有成型API提供自定义validator。这一点Vue只有v-model和第三方库。对于后台之类的重表单应用,还是Ng2有优势。
2. 依赖注入
无论喜不喜欢DI,这就是Angular2的强大功能之一。有DI可以在不改变代码结构的情况下完成功能替换。(如,在desktop和mobile有不同功能,可以通过注入不同service实现,而共用相同的template和directive)。Vue则需要程序员自己规划代码组织,用来支持共享组件。DI也可以用于类似module local state的功能。比如,一个视频播放控件有几个子组件完成,子组件需要分享一个状态。这一点Angular2有原生的service injection pattern。而Vue则没有官方推荐。
3. 对标准向后兼容
Angular2在一些细节上对标准有更好的支持。比如 list differ 算法中 Angular2 可以支持实现了Symbol.iterator的对象,而Vue只能支持Array。对Observable和Promise,Angular2在应用的各个地方,甚至模板级别都有支持(async pipe)。而Vue需要vue-rx等第三方库支持。Angular2的组件有shadow dom的实现可以选择,而Vue目前还没有。
The advantages of Angular2 over Vue have been weakened a lot after Vue2.0. For example, SSR (Vue2 already supports it natively) and full-stack frameworks (officially recommend Vuex+Vue-Router), and Alibaba's weex is also available on the native side.
However, Angular2 is still beyond the reach of Vue in terms of completeness and coverage of API design. There are mainly the following points
1. Angular2 native Form support:
Angular2's native Form module is quite powerful. In addition to basic functions such as two-way binding, it can also control the form behavior of DOM elements through programatic API. There is also a molding API to provide custom validators. Vue only has v-model and third-party libraries for this. For heavy form applications such as backends, Ng2 still has an advantage.
2. Dependency injection
Whether you like DI or not, this is one of the powerful features of Angular2. With DI, you can complete function replacement without changing the code structure. (For example, different functions on desktop and mobile can be implemented by injecting different services, while sharing the same template and directive). Vue requires programmers to plan the code organization themselves to support shared components. DI can also be used for functions similar to module local state. For example, a video playback control is completed by several sub-components, and the sub-components need to share a state. Angular2 has a native service injection pattern for this. Vue has no official recommendation.
3. Backward compatibility with standards
Angular2 has better support for standards in some details. For example, in the list differ algorithm, Angular2 can support objects that implement Symbol.iterator, while Vue can only support Array. For Observable and Promise, Angular2 has support (async pipe) in various places of the application, even at the template level. Vue requires support from third-party libraries such as vue-rx. Angular2 components have shadow dom implementations to choose from, but Vue does not yet have it.