新建角,我试图按照JSLint的(由Douglas Crockford的书面)的JS都没有使用this
的建议。如何不在Angular中使用'this'?
如何防止自己的角度使用this
?到目前为止,我所见过的所有教程都依赖于使用this
,SO搜索导致无法回答。
对于被清晰的目的,让我们假设我试图写该控制器:
app.controller('StoreController', function() {
this.products = {};
});
我如何可以访问的控制对象,以便我可以添加products
财产?
var my_controller = app.controller('StoreController', function() {
});
my_controller.products = {}; // Maybe like this?
角度(和大多数其他框架)将不适用于该建议。 – SLaks
首先,'this'不用于标准控制器。您使用'$ scope',将'$ scope'注入到控制器中并独占使用它。我唯一一次使用'this'是在服务中。 – DataHerder
只要您适当地使用'this',没有什么问题。 –