AngularJS中的templateUrl与模板 [英] templateUrl vs template in AngularJS

查看:124
本文介绍了AngularJS中的templateUrl与模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为对于路由,应始终在 template 上使用 templateUrl 。但是对于指令,何时应该使用 templateUrl 代替 template ?我看到有些人将字符串形式的HTML块用作 template ,而其他人则将所有指令链接到 templateUrl ,即使模板确实非常简单而且很小。

I think for routing, templateUrl should always be used over template. But for a directive, when should templateUrl be used instead of template? I see some people use chunks of HTML in string format as template, whereas others link all their directives to a templateUrl, even if the template is really simple and small.

因此,确定使用哪个模板的最佳实践是什么?无论模板的复杂程度如何,我个人更赞成使用 templateUrl ,这是因为我讨厌将HTML放入字符串中,但是我希望了解除主观情感之外的原因。

So, what is the best practice for deciding which one to use? I am personally more in favour of using templateUrl regardless of the template's complexity, just because I hate putting HTML in strings, but I would love to learn about reasons beyond just subjective emotions.

推荐答案

实际上,它取决于偏好。总的来说,我同意您的观点,由于易于编辑,在单独的模板中进行更复杂的标记总是更有意义。

It cones down to preference, really. In general I agree with you, and more complex markup always makes more sense in a separate template due to ease of editing.

这篇关于AngularJS中的templateUrl与模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆