Angular: Render externalized strings containing scope variables in the controller

一曲冷凌霜 提交于 2021-01-28 02:22:52

问题


Is it possible to render externalized strings (passed from server in my case) in the controller?

My use case: I'm using angular-toastr as an alert service, and I must pass message and title to the toastr object. The tricky part is when the strings contain scope variables, e.g: stringFromServer = "Something with {{someVariable}} went wrong".

I know in my HTTP callback about the someVariable but I want to render it to the string before passing it as a message to the alert service.

Is this possible, and what would be the best way?


回答1:


Assuming the server can render the string with a $scope.variable placeholder, $interpolate seems like what you're looking for.

Please see documentation



来源:https://stackoverflow.com/questions/32198050/angular-render-externalized-strings-containing-scope-variables-in-the-controlle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!