Reputation: 1294
I am working on localization within my angular project. It reads a JSON file which is having key and it's localized value in string.
Like: text1:"Localized text"
This prints "Localized text" on page correctly. But when I need to add some dynamic text in the string, like:
text1: "Showing page {{cur_page_num}} of {{total_pages}} pages"
where the cur_page_num
and total_pages
values will come from controller. I have tried
"Showing page {{cur_page_num}} of {{total_pages}} pages"
but it's printing {{cur_page_num}}
and {{total_pages}}
as it is without evaluating it.
Upvotes: 0
Views: 56
Reputation: 12103
use ng-bind-html
EX:
<p ng-bind-html="obj.text1"></p>
At this point you may get an error.
attempting to use an unsafe value in a safe context error
you need to either use ngSanitize
or $sce
to resolve that.
Upvotes: 2
Reputation: 297
try storing the json values in an array . iterate it on html & render it there .
Upvotes: 1
Reputation: 1104
if it is from template then your code should be like this,
text1: "Showing page " + {{cur_page_num}} + " of " + {{total_pages}} + " pages"
or if it is from controller then it can be like below,
text1: "Showing page " + $scope.cur_page_num + " of " + $scope.total_pages + " pages"
Upvotes: 0