Recognize variables of a string that is defined as string Angular.js [1.6]

0

How can I achieve the following ..

$scope.id = 2;
$scope.name = 'jhon';
$scope.render = "<b>{{id}} - {{name}}</b>";
..
<p ng-bind-html='render'></p>

There is something like this in php printf ('text and other% s more fill text% s a little more.', $ var1, $ var2); which would also be good if it existed in angularjs to obtain the desired result.

    
asked by Kung-Fu Panda 10.07.2018 в 16:05
source

2 answers

0

If you are using ES6 you could do something like that

$scope.id = 2;
$scope.name = 'jhon';
$scope.render = '<b>${id} - ${name}</b>';
..
<p ng-bind-html='render'></p>

This is called Text Interpolation if you want to do a deeper search.

    
answered by 10.07.2018 в 16:38
0

I solved it in the following way

if (!String.prototype.fprintFormat) {
    String.prototype.fprintFormat = function() {
        return [...arguments].reduce((p,c) => p.replace(/%s/,c), this);
    };
}

and to call it, as follows: ng-bind-html="col.render.fprintFormat (row [value1]))"

    
answered by 11.07.2018 в 06:01