Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: ng-placeholder not working

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'}}">

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'" 

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.

like image 282
user3407039 Avatar asked Jun 01 '15 12:06

user3407039


People also ask

Why placeholder is not working in angular?

If your placeholder is not working then it simply means that you have assigned them some value to that input. In your case, I am 100% sure that {{ d. placeholder }} holds some value( might be value equal to ' '). Assign this value to NULL.

What is placeholder in angular?

Placeholders can be used to enhance the experience of your application. You will, need set some custom widths to toggle their visibility. Their appearance, color, and sizing can be easily customized with our utility classes.


2 Answers

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'}}" />

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

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

like image 69
Oskar Lindberg Avatar answered Oct 09 '22 11:10

Oskar Lindberg


You can try this:

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

ng-attr- will work with any HTML attribute.

like image 32
Hussain Avatar answered Oct 09 '22 10:10

Hussain