AngularJS:ng-占位符不起作用 [英] AngularJS: ng-placeholder not working

查看:398
本文介绍了AngularJS:ng-占位符不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下输入html元素,我想根据用户模型中保存的内容来更改占位符.

I have the following input html element that I want to change the placeholder of depending on what is being held in my user model.

<input type="text" class="form-control" id="Username" name="Username" data-ng-model="user.Username" required="" ng-placeholder="{{user.AdAccount ? 'Username' : 'Ad Login'}}">

我什至尝试过这种方法,据说该方法在以前的angular版本中有效,但是没有成功.

I even tried this method that is said to have worked in previous versions of angular, but no success.

ng-placeholder="user.AdAccount == true && 'Username' || 'AD Login'" 

此刻,我的占位符似乎完全空白.我也知道AdAccount正确持有true/false,因为它已在ng-show表单上的其他地方使用.

At the moment my placeholder just appears completely blank. I also know that AdAccount is holding true/false correctly because it is being used elsewhere on the form with ng-show.

推荐答案

我认为没有ngPlaceholder指令.尝试将代码更改为:

I don't think there's any ngPlaceholder directive. Try changing your code to:

<input type="text" class="form-control" id="Username" name="Username" data-ng-model="user.Username" required="" placeholder="{{user.AdAccount ? 'Username' : 'Ad Login'}}" />

也就是说,将ng-placeholder更改为placeholder,一切都会正常工作.

That is, change ng-placeholderinto just placeholder, and everything should work fine.

(如果需要符合有效的XHTML,也请注意自闭斜杠.)

(Note also the self-closing slash if you need to conform to valid XHTML.)

这篇关于AngularJS:ng-占位符不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆