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.