替代Angular 2.0中的$ scope [英] Alternative to $scope in Angular 2.0

查看:69
本文介绍了替代Angular 2.0中的$ scope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Angular 2.0中,将没有$scope.

In Angular 2.0, there will be no $scope.

有什么替代方法?如何在组件之间共享数据? scope选项在指令中可用吗?实际上,是否有我可以熟悉的替代方法?

What is the alternative to that? How will I be able share data between the components? Will the scope option be available in directives? More practically, is there a current alternative to that that I can get acquainted with?

我知道controller as,但我知道控制器也将被淘汰.

I am aware of controller as but I read that controllers will be eliminated too.

对这样的革命感到困惑,Angular团队已经开始.

Confused on such a revolution the Angular team has started.

推荐答案

Angular 2.0 使用的是this而不是$scope.

2.0中的主要变化之一是控制器的消亡,以及对组件的新强调. 转向基于组件的应用程序的最大优势是定义它们的界面更容易.另外,HTML元素在事件,属性和属性上已经具有易于映射的界面.

One of the major changes coming in 2.0 is the death of the controller, and a new emphasis on components. Big advantage of moving towards component-based apps is that it's easier to define their interfaces; plus, HTML elements already have an easily mappable interface in events, attributes, and properties.

请参见将 AngularJS 1.3 迁移到 2.0 此处. 另请参见 Angular 2.0 的完整文档

See the Migration of AngularJS 1.3 to 2.0 here. Also see the complete documentation of Angular 2.0 here

这篇关于替代Angular 2.0中的$ scope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆