【问题标题】:default text when the input is empty in angular for label while binding绑定时标签的角度输入为空时的默认文本
【发布时间】:2016-09-14 00:52:43
【问题描述】:

我的这段代码运行良好,并根据从控制器接收到的数据显示到绑定中。但是,我尝试将服务器数据设置为 string.empty 并且我希望会出现这个默认文本“你的名字”,但事实并非如此。如果服务器返回空字符串,我希望显示默认文本。

<label for="name" class="label-proj" ng-bind="ctrl.name">Your name</label>

【问题讨论】:

    标签: angularjs angular angularjs-directive ng-bind-html ng-bind


    【解决方案1】:

    您可以执行以下操作:

    <label for="name" class="label-proj">{{ctrl.name || "Your name"}}</label>
    

    【讨论】:

    • 谢谢,让我快点试试,让你知道,因为我也想在(表头列)中使用它
    • 谢谢你,它在我需要的所有地方都像一个魅力 :) 干杯
    猜你喜欢
    • 2015-02-13
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 2013-02-25
    • 1970-01-01
    • 2010-11-09
    相关资源
    最近更新 更多