Javascript 切换<;a>;使用ng hide/show和布尔值时标记失败

Javascript 切换<;a>;使用ng hide/show和布尔值时标记失败,javascript,jquery,html,css,angularjs,Javascript,Jquery,Html,Css,Angularjs,我有一个向上箭头,它应该ng hideifthis。showUpArrow等于false,而ng showifthis。showUpArrow等于falsethis.showUpArrow在页面加载时设置为false,并且仅在页面顶部达到指定的div的偏移时切换为true。我正在让它识别当它到达divfine and dandy时,它应该将布尔值变为true。问题在于,当此项设置为true时,它没有显示我希望它显示的标记。showUpArrow设置为true。有什么好处 这是我的HTML… 值得

我有一个向上箭头,它应该
ng hide
if
this。showUpArrow
等于false,而
ng show
if
this。showUpArrow
等于false
this.showUpArrow
在页面加载时设置为
false
,并且仅在页面顶部达到指定的
div
偏移时切换为
true
。我正在让它识别当它到达
div
fine and dandy时,它应该将布尔值变为
true
。问题在于,当
此项设置为
true时,它没有
显示我希望它显示的
标记。showUpArrow
设置为
true
。有什么好处

这是我的HTML…


值得指出的是,我的
ng hide
ng show
语句的
landingControl
部分引用了我的控制器。我使用的是
this
方法,而不是
$scope
方法

您需要使用
$scope.apply
$timeout
调用摘要循环

$apply()
用于从角度框架外部执行角度表达式。(例如,来自浏览器DOM事件、setTimeout、XHR或第三方库)。因为我们正在调用angular框架,所以我们需要执行异常处理、执行监视的适当范围生命周期


这通常是在指令中完成的。

谢谢,这似乎是我需要的。你知道这种类型的代码在我看来是什么样子吗?那么你是不是建议我在指令中重新编写代码并调用
.apply()
?是的,然后将指令放在元素
id=mystory
上。这将是一种“有角度”的方式,不要忘记删除scopedestroy中的滚动处理程序event@georgeawg我遇到的问题是,该指令在页面加载时只编译一次。它并不是像它需要的那样,每次用户向下滚动时都检查页面上的位置。有什么想法吗?
<a href='' id='up-arrow-link' ng-click='landingControl.goToAnchor("wrapper")'>
    <img id='up-arrow' src='../static/images/uparrow.png' ng-hide='!landingControl.showUpArrow' ng-show='landingControl.showUpArrow'>
</a>
myModule.controller('landingController', function($location, $anchorScroll, $window){
var _this = this;
this.showUpArrow = false;

    angular.element($window).bind("scroll", function() {
        var elem = angular.element('#mystory')[0].offsetTop
        var topOfScreen = $window.scrollY;
        if (topOfScreen >= elem) {
            _this.showUpArrow = true;

        }
    });
})