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

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

问题描述

在 Angular 2.0 中,将没有 $scope.

有什么替代方案?我将如何能够在组件之间共享数据?scope 选项在指令中可用吗?更实际的是,目前有没有我可以熟悉的替代方法?

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

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

解决方案

Angular 2.0 正在使用 this 而不是 $scope.

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

查看 AngularJS 1.32.0 的迁移 此处.另请参阅 Angular 2.0 的完整文档 这里

In Angular 2.0, there will be no $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?

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

Confused on such a revolution the Angular team has started.

解决方案

Angular 2.0 is using this instead of $scope.

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.

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天全站免登陆