Why am I getting different results from ng-show=“!emptyArray” and ng-hide=“emptyArray”?

前端 未结 3 464
深忆病人
深忆病人 2020-12-30 00:53

I have always thought ngShow and ngHide act as boolean counterpart to each other. That belief, however, is shaken by the unexpected behaviour of

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-30 01:26

    ng-if and ng-show mistreats "[]" (empty array)

    See: this link

    [] == true
    false
    
     [] != true
     true
    
    (![]) == true
    false
    
    [''] == true
    false
    
    (!['']) == true
    false
    
    "" == true
    false
    
    "[]" == true
    false
    
    (!"[]") == true
    false
    

    Sounds its by design.

提交回复
热议问题