String Expression in AngularJS with Examples

  Total Views : 913
  Comments : 0
 
  Keywords : Angularjs string expressions example, How to use angularjs string expressions with example, Learn string expressions in angularjs with examples

Here we will learn what are the string expressions in angularjs and how to use string expressions in angularjs with example.

String Expressions in AngularJs

The string expression in angularjs is a unit of code to perform operations on string values. We will see how to use string expressions in angularjs with example

Example of String Expressions in AngularJS

Create or add a HTML page (say index.html) in your application. After adding index.html page add following sample code of angularjs string expressions in header section of your page. 

 

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<script type="text/javascript">

var app = angular.module('expressionApp', [])

app.controller("expressionController", function ($scope) {

$scope.expression1 = "Welcome to ";

$scope.expression2 = "Tutlane.com"

});

</script>

Write the following code under starting of body tag <body> for string expression in angularjs like as shown below.

 

<body ng-app="expressionApp">

<form id="form1">

<div ng-controller="expressionController">

<div>String  Expression</div>

<p>Hello: {{expression1+" "+expression2}}</p>

</div>

</form>

</body>

Following is the full example code for string expressions in angularjs with live demo as show below

 

Live Preview

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>String Expressions of AngularJs</title>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<script type="text/javascript">

var app = angular.module('expressionApp', [])

app.controller("expressionController", function ($scope) {

$scope.expression1 = "Welcome to ";

$scope.expression2 = "Tutlane.com"

});

</script>

</head>

<body ng-app="expressionApp">

<form id="form1">

<div ng-controller="expressionController">

<div>String  Expression</div>

<p>Hello: {{expression1+" "+expression2}}</p>

</div>

</form>

</body>

</html>

Now run above code of string expressions in angularjs example and check output that will be like as shown below

Output of AngularJS String Expressions

Following is the result of angularjs string expressions example.

 

Angularjs string expressions example output or result

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User