Skip to main content
added 13 characters in body
Source Link
xkeshav
  • 54.2k
  • 47
  • 183
  • 254

How to interpolate value inside interpolate?

I am using a file where I have written message string and using {{ vm.variable }} but I am unable to display the string with variable value on HTML.

input string ( in JS ): "Welcome {{name}} to the World."

desired output string (in HTML ): "Welcome John Smith to the world."

look my code below

(function() {

    'use strict';

    angular
        .module('app', [])
        .value('_MSG_', {
                "signup": "Welcome {{name}} to the World.",
                "login": "last login from {{location}}"
        }).controller('MessageController', function($scope, $parse, $interpolate, _MSG_){
            var vm = this;
            vm.name = "John Smith";
            vm.location = "India";
            vm.welcomeMessage = _MSG_.signup;
            //========trial 1 =======
            // vm.finalString = $interpolate(vm.welcomeMessage); 
            // nothing happens but
            //=====trial 2=====
            // set {{vm.name}} in _MSG_.signup and do below
            // vm.finalString = $parse(_MSG_).assign($scope, vm.name);
            // ERROR [$parse:syntax] Syntax Error: Token '{' is an unexpected token at column 9 of the expression [Weclome {{vm.name}}.] starting at [{{vm.name}}.].
        });
})();
<html ng-app="app">
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="MessageController as vm ">
    {{ vm.welcomeMessage }} ==> Welcome John Smith to the world


    // trial 1

    {{ vm.finalString }}
</body>
</html>

How to interpolate value inside interpolate?

I am using a file where I have written message string and using {{ vm.variable }} but I am unable to display the string with variable value on HTML.

input string ( in JS ): "Welcome {{name}} to the World."

desired output string (in HTML ): "Welcome John Smith to the world."

look my code below

(function() {

    'use strict';

    angular
        .module('app', [])
        .value('_MSG_', {
                "signup": "Welcome {{name}} to the World.",
                "login": "last login from {{location}}"
        }).controller('MessageController', function($scope, $parse, $interpolate, _MSG_){
            var vm = this;
            vm.name = "John Smith";
            vm.location = "India";
            vm.welcomeMessage = _MSG_.signup;
            //========trial 1 =======
            // vm.finalString = $interpolate(vm.welcomeMessage); 
            // nothing happens but
            //=====trial 2=====
            // set {{vm.name}} in _MSG_.signup and do below
            // vm.finalString = $parse(_MSG_).assign($scope, vm.name);
            // ERROR [$parse:syntax] Syntax Error: Token '{' is an unexpected token at column 9 of the expression [Weclome {{vm.name}}.] starting at [{{vm.name}}.].
        });
})();
<html ng-app="app">
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="MessageController as vm ">
    {{ vm.welcomeMessage }} ==> Welcome John Smith


    // trial 1

    {{ vm.finalString }}
</body>
</html>

How to interpolate value inside interpolate?

I am using a file where I have written message string and using {{ vm.variable }} but I am unable to display the string with variable value on HTML.

input string ( in JS ): "Welcome {{name}} to the World."

desired output string (in HTML ): "Welcome John Smith to the world."

look my code below

(function() {

    'use strict';

    angular
        .module('app', [])
        .value('_MSG_', {
                "signup": "Welcome {{name}} to the World.",
                "login": "last login from {{location}}"
        }).controller('MessageController', function($scope, $parse, $interpolate, _MSG_){
            var vm = this;
            vm.name = "John Smith";
            vm.location = "India";
            vm.welcomeMessage = _MSG_.signup;
            //========trial 1 =======
            // vm.finalString = $interpolate(vm.welcomeMessage); 
            // nothing happens but
            //=====trial 2=====
            // set {{vm.name}} in _MSG_.signup and do below
            // vm.finalString = $parse(_MSG_).assign($scope, vm.name);
            // ERROR [$parse:syntax] Syntax Error: Token '{' is an unexpected token at column 9 of the expression [Weclome {{vm.name}}.] starting at [{{vm.name}}.].
        });
})();
<html ng-app="app">
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="MessageController as vm ">
    {{ vm.welcomeMessage }} ==> Welcome John Smith to the world


    // trial 1

    {{ vm.finalString }}
</body>
</html>

added 143 characters in body
Source Link
xkeshav
  • 54.2k
  • 47
  • 183
  • 254

How to interpolate value inside interpolate?

I am using a file where I have written message string and using {{ vm.variable }} but I am unable to display the string with variable value on HTML.

input string ( in JS ): "Welcome {{name}} to the World."

desired output string (in HTML ): "Welcome John Smith to the world."

look my code below

(function() {

    'use strict';

    angular
        .module('app', [])
        .value('_MSG_', {
                "signup": "Welcome {{name}} to the World.",
                "login": "last login from {{location}}"
        }).controller('MessageController', function($scope, $parse, $interpolate, _MSG_){
            var vm = this;
            vm.name = "John Smith";
            vm.location = "India";
            vm.welcomeMessage = _MSG_.signup;
            //========trial 1 =======
            // vm.finalString = $interpolate(vm.welcomeMessage); 
            // nothing happens but
            //=====trial 2=====
            // set {{vm.name}} in _MSG_.signup and do below
            // vm.finalString = $parse(_MSG_).assign($scope, vm.name);
            // ERROR [$parse:syntax] Syntax Error: Token '{' is an unexpected token at column 9 of the expression [Weclome {{vm.name}}.] starting at [{{vm.name}}.].
        });
})();
<html ng-app="app">
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="MessageController as vm ">
    {{ vm.welcomeMessage | }} ==> Welcome John Smith


    // trial 1

    {{ vm.finalString }}
</body>
</html>

How to interpolate value inside interpolate?

I am using a file where I have written message string and using {{ vm.variable }} but I am unable to display the string with variable value on HTML.

look my code below

(function() {

    'use strict';

    angular
        .module('app', [])
        .value('_MSG_', {
                "signup": "Welcome {{name}} to the World.",
                "login": "last login from {{location}}"
        }).controller('MessageController', function($scope, $parse, $interpolate, _MSG_){
            var vm = this;
            vm.name = "John Smith";
            vm.location = "India";
            vm.welcomeMessage = _MSG_.signup;
            //========trial 1 =======
            // vm.finalString = $interpolate(vm.welcomeMessage); 
            // nothing happens but
            //=====trial 2=====
            // set {{vm.name}} in _MSG_.signup and do below
            // vm.finalString = $parse(_MSG_).assign($scope, vm.name);
            // ERROR [$parse:syntax] Syntax Error: Token '{' is an unexpected token at column 9 of the expression [Weclome {{vm.name}}.] starting at [{{vm.name}}.].
        });
})();
<html ng-app="app">
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="MessageController as vm ">
    {{ vm.welcomeMessage | }} ==> Welcome John Smith


    // trial 1

    {{ vm.finalString }}
</body>
</html>

How to interpolate value inside interpolate?

I am using a file where I have written message string and using {{ vm.variable }} but I am unable to display the string with variable value on HTML.

input string ( in JS ): "Welcome {{name}} to the World."

desired output string (in HTML ): "Welcome John Smith to the world."

look my code below

(function() {

    'use strict';

    angular
        .module('app', [])
        .value('_MSG_', {
                "signup": "Welcome {{name}} to the World.",
                "login": "last login from {{location}}"
        }).controller('MessageController', function($scope, $parse, $interpolate, _MSG_){
            var vm = this;
            vm.name = "John Smith";
            vm.location = "India";
            vm.welcomeMessage = _MSG_.signup;
            //========trial 1 =======
            // vm.finalString = $interpolate(vm.welcomeMessage); 
            // nothing happens but
            //=====trial 2=====
            // set {{vm.name}} in _MSG_.signup and do below
            // vm.finalString = $parse(_MSG_).assign($scope, vm.name);
            // ERROR [$parse:syntax] Syntax Error: Token '{' is an unexpected token at column 9 of the expression [Weclome {{vm.name}}.] starting at [{{vm.name}}.].
        });
})();
<html ng-app="app">
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="MessageController as vm ">
    {{ vm.welcomeMessage }} ==> Welcome John Smith


    // trial 1

    {{ vm.finalString }}
</body>
</html>

Source Link
xkeshav
  • 54.2k
  • 47
  • 183
  • 254

interpolate string with variable name in angularjs

How to interpolate value inside interpolate?

I am using a file where I have written message string and using {{ vm.variable }} but I am unable to display the string with variable value on HTML.

look my code below

(function() {

    'use strict';

    angular
        .module('app', [])
        .value('_MSG_', {
                "signup": "Welcome {{name}} to the World.",
                "login": "last login from {{location}}"
        }).controller('MessageController', function($scope, $parse, $interpolate, _MSG_){
            var vm = this;
            vm.name = "John Smith";
            vm.location = "India";
            vm.welcomeMessage = _MSG_.signup;
            //========trial 1 =======
            // vm.finalString = $interpolate(vm.welcomeMessage); 
            // nothing happens but
            //=====trial 2=====
            // set {{vm.name}} in _MSG_.signup and do below
            // vm.finalString = $parse(_MSG_).assign($scope, vm.name);
            // ERROR [$parse:syntax] Syntax Error: Token '{' is an unexpected token at column 9 of the expression [Weclome {{vm.name}}.] starting at [{{vm.name}}.].
        });
})();
<html ng-app="app">
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="MessageController as vm ">
    {{ vm.welcomeMessage | }} ==> Welcome John Smith


    // trial 1

    {{ vm.finalString }}
</body>
</html>