I am trying to replace string words which are enclosed in $
with values of JSON.
For example:
I have json.
$scope.data = {
name: "Some Name",
user: "User Name",
designation: "Designation",
fullName:"User Full Name"
}
And I have String:
$scope.str="User name of $user$ is $name$ and designation is $designation$";
Is there any angular method from which I can directly replace variables from this string?
I tried using loop through keys and verifying, It is working but there are more than 100 keys in json and there might be less than 20 keys will get used in string.
I am expecting a better approach which improve performance.
1). String.prototype.replace. It actually makes sense to do it in pure Javascript with String.prototype.replace method, it's going to be more effective. For example like this:
$scope = {};
$scope.data = {
name: "Some Name",
user: "User Name",
designation: "Designation",
fullName: "User Full Name"
};
$scope.str = "User name of $user$ is $name$ and designation is $designation$";
$scope.str = $scope.str.replace(/\$(\w+)\$/g, function(a, b) {
return typeof $scope.data[b] !== 'undefined' ? $scope.data[b] : '';
});
alert($scope.str);
How to unescape string escaped using StringEscapeUtils in front end. Thank you PS: I use EXT-js3.4 & Jsp.
How to unescape string escaped using StringEscapeUtils in front end. Thank you PS: I use EXT-js3.4 & Jsp.
I have tabs in Bootstrap: <ul class="nav nav-tabs" role="tablist"> <li>tab1</li> <li>tab2</li> <li>tab3</li> <li>tab4</li> <li>...
I have tabs in Bootstrap: <ul class="nav nav-tabs" role="tablist"> <li>tab1</li> <li>tab2</li> <li>tab3</li> <li>tab4</li> <li>...
I am having some difficulties with this problem. I want to render some html elements given a tree structure. For example this javascript tree object: let htmlTree = { id: "a", children: [{ ...
I am having some difficulties with this problem. I want to render some html elements given a tree structure. For example this javascript tree object: let htmlTree = { id: "a", children: [{ ...
For dynamic page changes without having to reload the whole content, I have found this very simple working solution: Tutorial: http://css-tricks.com/rethinking-dynamic-page-replacing-content/ Demo: ...
For dynamic page changes without having to reload the whole content, I have found this very simple working solution: Tutorial: http://css-tricks.com/rethinking-dynamic-page-replacing-content/ Demo: ...