[email protected]      beta
Donate

String expressions in AngularJS

Overview: Understanding String Expressions in AngularJS, What is String Expressions, AngularJS string expression example, AngularJS binds data to HTML using Expressions.

AngularJS String Expressions

String Expressions are same as JavaScript strings. The string expression is used to perform operations on string values, e.g. ( string concatenations, string merge). AngularJS resolves the expression, and return the result output where they have applied in a web-page.

AngularJS example using string expressions.

Example 1 : Here we are going to concatenate user name using string expressions. The code looks like as written below.

<div ng-app="">
    <p>  My FullName is {{ "Satinder" + " " +"singh" }} </p>
</div>

Same example can also be written using ng-bind directive in angularjs. Final code looks like as writte below.

<div ng-app="">
    <p> My FullName is  <span ng-bind="Satinder" +" " +"singh" > </span> </p>
</div>

Output: My FullName is Satinder Singh

Try It Yourself ⇒


Example 2 : Here we are going to read data from ng-init and concatenate it using string expressions. The code looks like as written below.

<div ng-app="" ng-init="firstName='Satinder';lastName='Singh'" >
    <p> My FullName is  {{ firstName + +lastName" }} </p>
</div> 

Same example can also be written using ng-bind directive in angularjs. Final code looks like as writte below.

<div ng-app="" ng-init="firstName='Satinder';lastName='Singh'" >
    <p> My FullName is  <span ng-bind="firstName + +lastName" > </span> </p>
</div>

Output: My FullName is Satinder Singh

Try is yourself


  Popular Tag
  Recent Posts
  Follow Us
If you find these tutorials helpful then please donate. It will lead me to do more tutorials.
Donate