AngularJS-2 change the delimiters {{}}


I'm trying to use something similar to interpolateProvider in AngularJS 2 but I can not find something similar to this:

AngularJS 1.x $ interpolateProvider


Looking at the documentation for AngularJS 2 I could not find anything like the above.

asked by Angel Angel 08.02.2016 в 22:32

2 answers


can be changed by including the interpolation property in @component, example:

import { Component } from '@angular/core';

    selector: 'my-app',
    templateUrl: './app/app.component.html',
    interpolation: ['[[', ']]']

export class AppComponent 
    title: string = "Angular 2 App";
    paragraph: string = "Nueva app con paso de variables";

with this we change the {{}} for [[]]

answered by 10.02.2017 / 21:40

From what I've seen it does not look like it's configurable (for now).

The only thing I have come to, looking at the code, is that they have defined an internal variable with the regular expression that would correspond to the expression of interpolation, worth the redundancy.

The code is this:

L51: modules / angular2 / src /core/change_detection/parser/parser.ts

// TODO(tbosch): Cannot make this const/final right now because of the transpiler...
var INTERPOLATION_REGEXP = /\{\{([\s\S]*?)\}\}/g;

L21: modules / angular2 / src / compiler / legacy_template .ts

var INTERPOLATION_REGEXP = /\{\{.*?\}\}/g;  

I do not know if changing the value of these variables could achieve what you are looking for (of course you would have to re-compile angular2 later).

Neither do I know if as it evolves they will make it configurable. If you are very interested, register an "issue" interested in the functionality (advantages of OSS projects) , then either listen to it or it is not something else.

I personally worry about the changes in the syntax for bindear events, ... although it seems that there are utilities to be able to migrate it or you can also mix ng1 and ng2. We will have to be attentive.

Update 10/02/2016: In the link that @AngelAngel has shared in the comments you can see how there is already an open Issue on this topic "Ability to change the interpolation delimiter character # 3682 "

answered by 10.02.2016 в 00:08