最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angularjs - Difference between interpolation and concatenation in JavaScript? - Stack Overflow

programmeradmin1浏览0评论

The language and library I'm using is JS and AngularJS. Am I right in assuming that "interpolation" and "concatenation" both means "bination of strings and variables"?

But "interpolation" is used when you're using the double curly brackets in AngularJS. And "concatenation" is used when you're using pure JS?

Or is there another diference that I missed?

EDIT: Is this interpolation or concatenation (I don't just put strings together but an a variable is resolved here)?

    var test1 = "Hello";
    var number = 2 + 3;
    console.log(test1 + " " + number);

Hmm.... I guess whenever I use AngularJS library to bine some expression, then it's interpolation, right?

The language and library I'm using is JS and AngularJS. Am I right in assuming that "interpolation" and "concatenation" both means "bination of strings and variables"?

But "interpolation" is used when you're using the double curly brackets in AngularJS. And "concatenation" is used when you're using pure JS?

Or is there another diference that I missed?

EDIT: Is this interpolation or concatenation (I don't just put strings together but an a variable is resolved here)?

    var test1 = "Hello";
    var number = 2 + 3;
    console.log(test1 + " " + number);

Hmm.... I guess whenever I use AngularJS library to bine some expression, then it's interpolation, right?

Share Improve this question edited Jul 4, 2015 at 11:37 thadeuszlay asked Jul 4, 2015 at 11:26 thadeuszlaythadeuszlay 3,0257 gold badges38 silver badges71 bronze badges 2
  • I think it's concatenation. – Kim Honoridez Commented Jul 4, 2015 at 11:37
  • Concatenation is general term for every programming language where as in angualr js interpolation is done by {{}} with the help of $interpolation service. – squiroid Commented Jul 4, 2015 at 11:39
Add a ment  | 

3 Answers 3

Reset to default 5

In Angular js interpolation helps in getting model render on the view. Where as concatenation is to allow the strings to be join together with '+' it may or may not include interpolation .

Example:-

{{}} --> interpolation

It allows your model to bind in view:-

Model:-  $scope.name="rachit";

   View:-  <div>{{name}}</div>

   result in View after rendering :- <div>rachit</div>

'+'-->concatenation

It allows to concat the values either in view or in controller or even inside interpolation.

Controller:-
$scope.name="rachit"+"gulati";

View
<div>{{name+name}}</div> //Here interpolation also es into picture.
result:-"<div>rachitgualtirachitgualti</div>"

UPDATE 1:-

EDIT: Is this interpolation or concatenation (I don't just put strings together but an a variable is resolved here)?

var test1 = "Hello";
var number = 2 + 3;
console.log(test1 + " " + number);

It is simple concatenation in javascript here angular is not e into picture.

UPDATE 2:-

Hmm.... I guess whenever I use AngularJS library to bine some expression, then it's interpolation, right?

Concatenation is general term for every programming to concat two strings together.Where as in angualr js interpolation is done by {{}} with the help of $interpolation service.

Interpolation

Interpolation does mean that you want to get the code from the angular scope and show it on html page like suppose we have {{somevariable}} In this eg. it will evaluate the function in angular scope using $interpolation service.

Concatenation

It is used when you want to bind to two strings, It could be do it inside interpolation {{}} directive like {{someVariable + ' test'}} it will concate variable with test result would be someVariable test

Interpolation basically means that an expression gets resolved and concatenation is when you put a string together.

发布评论

评论列表(0)

  1. 暂无评论