简体   繁体   English

多个角度指令引用同一模板

[英]Multiple angular directives referring to the same template

I've found myself in a situation where I have 2 isolate scope directives (each managing differentiated scope and dom state) that are referring to a single template. 我发现自己处于以下情况:我有2个单独的作用域指令(每个指令分别管理不同的作用域和dom状态),它们均指向一个模板。

.directive1...
    scope: {},
    templateUrl: 'template1',

.directive2...
    scope: {},
    templateUrl: 'template1',

I'm used to having a 1-to-1 relationship between my directives and their templates, and this model (2 directives - to - 1 template) has me veering from that pattern. 我习惯于在我的指令和它们的模板之间建立一对一的关系,而这个模型(从2个指令-到-1个模板)使我偏离了这种模式。

Is there a good reason I shouldn't have multiple isolate scope directives referring to the same template? 是否有充分的理由我不应有多个隔离作用域指令引用同一模板?

Is this in violation of some 'best practices' design pattern thought? 这是否违反某些“最佳实践”设计模式?

Are there other design considerations I should be taking into account here? 在这里我还有其他设计考虑因素吗?

If directive1 and directive2 are very similar in form and function, I don't see any issue in reusing the same template. 如果指令1和指令2在形式和功能上非常相似,则在重用同一模板时不会出现任何问题。 Although, if they are so similar it may mean that they should be one directive with parameters/options passed on the scope? 虽然,如果它们是如此相似,可能意味着它们应该是在范围内传递了参数/选项的一个指令?

I would add that it would need to be very clear in the naming of all directives/templates involved in the 2-to-1 situation that they are similar, ex: 'apple' directive and 'orange' directive both use the 'fruit' template, similar to a class inheritance pattern. 我要补充一点,在涉及2比1情况的所有指令/模板的命名中,必须非常清楚它们的相似之处,例如:“ apple”指令和“ orange”指令都使用“ fruit”模板,类似于类继承模式。

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

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