5

I have an AngularJS expression enwrapped in a <a> tag. The expression is evaluating an allow variable.

<a href="#" >{{allow}}</a>

In case allow is null or undefined Angular shows nothing. Instead I would like to display a default string.


To give you a better understanding, this is what I'm trying to achieve.

enter image description here

The modal on the right is generated from the form on the left. If the user didn't enter any text for "Allow Button Text" and "Disallow Button Text" I want to display ALLOW and DON'T ALLOW respectively.

Here is my code:

<div id="test2" class="row"  ng-app="">    
  <label for="title">Title</label>
  <input type="text" name="title" ng-model="title" placeholder="https:/your website.com/wants to:">

  <label for="title">Allow Button Text</label>
  <input type="text"  ng-model="allow" placeholder="ALLOW">

  <label for="title">Disallow Button Text</label>
  <input type="text"  ng-model="disallow" placeholder="DONT ALLOW">     

  <p>{{title}}</p>
  <a href="" >{{disallow}}</a>
  <a href="" >{{allow}}</a>
1
  • 1
    What do you mean by "placeholder" in this context? Show an example of what you mean. Commented Feb 18, 2016 at 7:33

2 Answers 2

13

If by placeholder you mean default value until allow is specified, then it's quite easy:

<a href="#">{{ allow || 'Click me' }}</a>
Sign up to request clarification or add additional context in comments.

2 Comments

Shouldn't it be {{allow || 'Click me'}}? The single pipe | introduces a filter in Angular.
thnks @Gpx, this is what i want to do.
0

Sorry my friend, But placeholder attribute is not for anchor tag. It is for input fields.

let us know what you exactly want to achieve with this and we can suggest some alternative approach.

As suggested by @dfsq, if you mean placeholder text as the text to show when allow is not defined then you can put default text like this:

{{allow | 'placeholder text'}} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.