是否可以在同一个 HTML 元素上有多个指令? [英] Is it possible to have multiple directives on the same HTML element?

查看:36
本文介绍了是否可以在同一个 HTML 元素上有多个指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在同一个 HTML 元素上有两个不同的指令?

或者这会导致范围问题吗?

解决方案

是的,你可以,而且很常见.范围的唯一潜在问题是您不能在同一元素上拥有多个新范围.根据 angular 文档:如果同一元素上的多个指令请求一个新范围,则只会创建一个新范围."http://docs.angularjs.org/guide/directive

Is it possible to have two different directives on the same HTML element?

<div directiveone directivetwo></div>

or will that cause scope issues?

解决方案

Yes you can and it's fairly common. The only potential issue with scope is you can't have multiple new scopes on the same element. Per the angular docs: "If multiple directives on the same element request a new scope, only one new scope is created." http://docs.angularjs.org/guide/directive

这篇关于是否可以在同一个 HTML 元素上有多个指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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