角JS:控制器别名不工作 [英] Angular js : controller alias not working

查看:97
本文介绍了角JS:控制器别名不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用在同一个页面多个控制器,因此该code是清晰的,每个控制器我增加了一个别名。但是,当我使用别名,我无法访问的属性,功能。

I'm using many controllers in the same page, and so that the code is clearer, for each controller I added an alias. But, when I'm use an alias, I can't access properties, functions.

这code效果很好

这code不起作用

有什么区别吧。

推荐答案

在使用控制器构造,可以定义使用控制器的这个作用域属性,而不是 $范围对象。所以你的第二个例子控制器应该是:

When using the "controller as" construct, you define properties using the controller's this scope rather than the $scope object. So your controller for the second example should be:

function MyCtrl($scope) {
    this.items = m;
}

在你的榜样,你甚至都不需要注入 $范围,因为你不使用它,所以你可以削减下来,甚至更多:

In your example, you don't even need to inject $scope because you aren't using it, so you could pare it down even more to:

function MyCtrl() {
    this.items = m;
}

这篇关于角JS:控制器别名不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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