Angular js - 将FALSE值打印为字符串

时间:2014-02-18 10:17:08

标签: javascript angularjs views params rootscope

我只是尝试打印出一个FALSE的参数值,它打印出“false”作为纯文本,非常难以置信......任何线索?

   $rootScope.session = {
                "username" : $window.localStorage['user_username'] || false,
                "id_user" : $window.localStorage['user_id'] || false,
                "token" : $window.localStorage['user_session_token']
            }
    //in view
    <div>{{session.username}}</div>

2 个答案:

答案 0 :(得分:3)

尝试使用ng-if指令:

<div ng-if="session.username">{{session.username}}</div>

答案 1 :(得分:2)

Angular.js可能会在打印值上调用toString()

false.toString();

以上结果为字符串"false"