angularjs – ng-if导致链接显示一秒然后消失.如何防止出现

前端之家收集整理的这篇文章主要介绍了angularjs – ng-if导致链接显示一秒然后消失.如何防止出现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
ng-if有时会导致我的页面上的链接在加载时显示,然后消失.

链接根本不应该显示,我假设ng-if语句尚未处理第二个我能够看到它.

有没有办法阻止链接或元素显示

我也猜测currentClass对象尚未加载,因此ng-if无法评估,但我试图将其默认为隐藏,直到ng-if可以解决.

<span ng-if="isFaculty && !currentClass.courseInformation.IsCustomCourse">
<a ng-href="{{$window.BasePath}}lms/class/{{$stateParams.classid}}/instructorguide/download">
<span class="cec-msword-icon"></span>Download Instructor Guide</a> 
<span>| </span>
</span>

解决方法

使用 ng-cloak.它是这样的:

CSS:

[ng\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak {
  display: none !important;
}

HTML:

<div ng-cloak> ... </div>

在你的情况下,它将是:

<span ng-cloak ng-if="isFaculty && !currentClass.courseInformation.IsCustomCourse">
<a ng-href="{{$window.BasePath}}lms/class/{{$stateParams.classid}}/instructorguide/download">
<span class="cec-msword-icon"></span>Download Instructor Guide</a> 
<span>| </span>
</span>

记得:

The directive can be applied to the element,but the preferred usage is to apply multiple ngCloak directives to small portions of the page to permit progressive rendering of the browser view.

猜你在找的Angularjs相关文章