Concat string in AngularJs


Concat string in AngularJs -There are many ways to concat two strings, You can use JavaScript concat() method to concat two or more than two strings in AngularJs. Here in this tutorial we are going to explain how you can join two or more than two strings in angularjs. You can also use our online editor to edit and run the code online.


How to Concat string in AngularJs | Join Strings Example

Let us go step by step to create an example to join strings in AngularJs using JavaScript Concat() method-

JavaScript Part

JavaScript Part Contains the following part as below –

Concat string in AngularJs :

 <script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
 $scope.str1 = 'Hello';
 $scope.str2 = 'World!';
 $scope.result = '';
 $scope.joinStr= function() {
     $scope.result = $scope.str1.concat($scope.str2);
 };
});
</script>

Html Part

Html Part contains the following html as below –

Angularjs Join Strings example:

<div ng-app="myApp">  
<div ng-controller="myController">  
<input type="button" ng-click="joinStr()" value="Click To Join"></br>
<p>Result = {{result}}</p>
       
 
</div> 
</div>

Complete Part

Now let us combine Html and JavaScript Together to create full example like this –

Angularjs Join Strings example

<!DOCTYPE html>
<html lang="en">
<head>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
 <script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
 $scope.str1 = 'Hello';
 $scope.str2 = 'World!';
 $scope.result = '';
 $scope.joinStr= function() {
     $scope.result = $scope.str1.concat($scope.str2);
 };
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController">  
<input type="button" ng-click="joinStr()" value="Click To Join"></br>
<p>Result = {{result}}</p>

       
 
</div> 
</div>
</body>  
</html>      

Try it »

If you run the above example it will produce output something like this –

Concat string in AngularJs


Advertisements

Add Comment

📖 Read More