我刚刚开始使用新版本的 Laravel angular。我试图在向下滚动页面时添加一些代码来更改 rootScope 变量。这就是我到目前为止所拥有的。
$onInit(){
this.$rootScope.showTestBanner = true;
var $rootScope = this.$rootScope;
angular.element(this.$window).bind("scroll", function() {
if (this.pageYOffset >= 20) {
this.$rootScope.showTestBanner = false;
}
});
}
问题是 this.$rootScope 在 angular.element 中未定义。我已经尝试在 angular.element 之外分配 this.$rootScope 以便它可以在绑定函数内部使用,但是数据绑定似乎确实有效。任何建议将不胜感激。如果答案很明显,请原谅我对 angular 1.5 和 ECMA6 很陌生。