gpt4 book ai didi

javascript - 使用 controllerAs 语法从 "this"访问指令的隔离范围

转载 作者:行者123 更新时间:2023-12-03 16:44:22 25 4
gpt4 key购买 nike

我无法使用 controllerAs 语法/样式从这里访问指令的独立作用域变量。

我可以使用 $scope 访问变量,但这似乎并不一致。有没有办法使用 this 访问隔离作用域的变量?

这是一个 gist我的 Controller 和指令。

最佳答案

由于您正在使用带有 Controller 作为语法的隔离范围指令并使用 angular 1.3,您现在可以通过打开 bindToController 轻松地将范围绑定(bind)绑定(bind)到 Controller 。 设置指令,以便范围绑定(bind)自动附加到 Controller 实例。在你的情况下:-

return {
scope: scope,
restrict: 'EA',
transclude: true,
template: getTemplate,
controller: 'PaginationCtrl',
controllerAs: 'pagination',
bindToController:true //<-- Here
};

关于javascript - 使用 controllerAs 语法从 "this"访问指令的隔离范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26558269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com