javascript 如何使用 Angular JS 重新渲染视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22217440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to re-render views using Angular JS
提问by nitansh bareja
I want to re-render all the views present on my page.I have Header, Footer and Body view. In Header view i have a dropDown in which user can select the Language Preference. On clicking on language prefrence all the view should be re-render. Is it Possible in Angular?
我想重新呈现我页面上的所有视图。我有页眉、页脚和正文视图。在标题视图中,我有一个下拉菜单,用户可以在其中选择语言首选项。单击语言偏好后,所有视图都应重新呈现。在 Angular 中可能吗?
In BackboneJs i simply call the render function again on that particular event. Is there some same kind of functionality provided by AngularJs?
在 BackboneJs 中,我只是在该特定事件上再次调用渲染函数。AngularJs 是否提供了某种相同的功能?
Thanks in Advance
提前致谢
Header Template (language Prefrence Dropdown Code)
标题模板(语言偏好下拉代码)
<li class="dropdown">
<a id="dLabel" role="button" data-toggle="dropdown" data-target="#">
Language Preferences<b class="caret"></b>
</a>
<ul class="dropdown-menu dropdown-manual">
<li id="English" ng-click="englishConversion()">English</li>
<li id="French" ng-click="frenchConversion()" >French</li>
</ul>
</li>
is there any inbuilt function which i can call in englishConversion and frenchConversion to re-render the view/views?
是否有任何内置函数可以在 englishConversion 和 frenchConversion 中调用以重新呈现视图/视图?
回答by Jayantha Lal Sirisena
Have you looked at the angular-getText libary,
你有没有看过angular-getText libary,
Or you can $compilethe HTML using angular again. You can simply do like this,
或者您可以再次使用 angular编译HTML。你可以简单地这样做,
var content=angular.element('#translatedContent');
var scope=content.scope();
$compile(content.contents())(scope));