WebInsight
WebInsight

Reputation: 307

Difference between expressions and interpolation markup with embedded expressions in angular

"Angular directive attributes take either expressions or interpolation markup with embedded expressions. It is considered bad practice to embed interpolation markup inside an expression".

I couldn't understand the difference between expressions and interpolation markup with embedded expressions. Please can someone explain ? I am new to angular.I checked the documentation but couldn't find the difference.

Upvotes: 3

Views: 1303

Answers (3)

LuLeBe
LuLeBe

Reputation: 584

An expression would be the "myscope" in ng-model="myscope"

And you can also do custom attributes like my-att="{{myscope}}"

edit: these expressions in curly braces are interpolated, meaning not the expression itself but its value gets passed into the directive. Your directive will thereby not have direct access to the scope property you used for the interpolation.

But you should not mix the two like ng-model="my{{scope}}"

I think that is what it refers to. This will often not work, since the scope is not yet initialized when the directive is parsed

Upvotes: 3

Indranil
Indranil

Reputation: 2723

Expression {{exp}}: Something that turns into some value.

Characteristics:

  1. It is processed by angular.
  2. Angular expression are tied to the scope they are in. It has access to the properties of $scope.
  3. Doesn't throws error if it has type error.
  4. Control flow function(e.g., 'If', 'else' statement etc) not allowed.
  5. Accept filter or a filter chain to format the output.

Interpolation (process): Process of replacing placeholders in a string with values.

Characteristics:

  1. In Angular, these placeholders are usually expressions.

  2. Result is automatically updated when placeholder changes. If $scope.message changes so will interpolation result will change.

Ex:

My name is {{ message }}

It is interpolated to: My name is Harry Potter

Upvotes: 1

Sourabh Jain 543
Sourabh Jain 543

Reputation: 208

Expression refers to Angular expression that may or may not contain double curly braces whereas interpolation markup means code inside this curly braces.

Upvotes: 3

Related Questions