简体   繁体   English

Angular JS单控制器多视图

[英]Angular JS single controller multiple views

Is it a good practice to have one controller, but two different html file templates that shows same data but in different format. 最好有一个控制器,但是有两个不同的html文件模板,它们显示相同的数据但格式不同。

Basically I need slightly different template to present the view on a modal dialog and different template to show when it is called on a web page. 基本上,我需要稍有不同的模板才能在模式对话框中显示视图,而在Web页面上调用时需要显示不同的模板。 Any suggestions, advice is appreciated. 任何建议,建议表示赞赏。

Thanks!! 谢谢!!

It is totally fine to share one controller between multiple views. 在多个视图之间共享一个控制器是完全可以的。 In fact this in one of the strengths of decoupling the javascript from the view like Angular code helps you do. 实际上,这是将javascript从与Angular代码这样的视图中分离出来的优势之一,可以帮助您做到这一点。 Different views can share the same logic but still render different markup. 不同的视图可以共享相同的逻辑,但仍呈现不同的标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM