Thomas
Thomas

Reputation: 34198

AngularJS: How to show single quote in expression

i am beginner in angular js. so i tried this code but output does not look good

<div ng-app>

    Write some text in textbox:
    <input type="text" ng-model="sometext" />

    <h1>Hello 
    <p ng-show="sometext">'</p>{{ sometext }}<p ng-show="sometext">'</p>
    </h1>

</div>

i want to show single quote around sometext expresion but if some test is null or empty then quote should not be shown. tell me how to achieve.

Upvotes: 2

Views: 821

Answers (2)

rgvassar
rgvassar

Reputation: 5811

Is there a reason why they're in two separate paragraph elements? Something like this should work:

<p ng-show="sometext">'{{ sometext }}'</p>

if you want the name to appear on the same line as "Hello", you'll have to change it to a span.

<span ng-show="sometext">'{{ sometext }}'</span>

Upvotes: 3

Hadi
Hadi

Reputation: 17299

try like this.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>

    Write some text in textbox:
    <input type="text" ng-model="sometext" />

    <h1>Hello 
    <p ng-show="sometext">{{'\''+sometext +'\''}}</p>
    </h1>

</div>

Upvotes: 0

Related Questions