2016-03-29 37 views
0

documentationng-hide說,它只是增加了一個CSS指令:角JS NG隱藏和非常大的圖像

<!-- when $scope.myValue is truthy (element is hidden) --> 
<div ng-hide="myValue" class="ng-hide"></div> 

<!-- when $scope.myValue is falsy (element is visible) --> 
<div ng-hide="myValue"></div> 

將其定義爲:

.ng-hide { 
    /* this is just another form of hiding an element */ 
    display: block!important; 
    position: absolute; 
    top: -9999px; 
    left: -9999px; 
} 

如果我有一個很大圖像,超過9999像素的任何維度,是不是會侵入視口?

有沒有任何安全隱患?由於隱藏元素仍然在DOM中,所以任何人都可以看到它。這是否意味着我應該使用ng-if來獲取敏感數據?

<div ng-if="userType == admin"> 
    < list of user names and passwords> 
+2

ngIf對於敏感數據來說似乎更合理 – shershen

回答

3

對於敏感數據,如果用戶無權查看敏感數據,則應確保它甚至不會進入應用程序。但ng-hide只是確實隱藏了內容,而ng-if只在符合條件時才呈現內容。

談到非常大的圖像,你總是會想要使用ng-if。繪製大圖像對您的應用程序有巨大的性能影響,在這種情況下使用ng-hide也會降低您的應用程序的速度。

+1

不是「只渲染」而是在DOM中放入或刪除塊,因爲ts寫道 – shershen

+0

我同意敏感數據,您如何看待非常大的圖像?它會泄漏到視口嗎? – Mawg

+1

將該部分添加到答案 –