简体   繁体   English

使用 Angular 组件/指令绑定的最有效方法是什么?

[英]What's the most efficient way to use Angular component/directive bindings?

I'm working on an app that has a large form with a large config object, with 25+ properties and several nested objects.我正在开发一个应用程序,它有一个大表单和一个大配置对象,有 25 个以上的属性和几个嵌套对象。 I'm trying to create a directive/component that populates several of these properties, and I was wondering if it's more efficient in terms of $$watchers to pass in the entire form/configuration object or those properties individually as bindings.我正在尝试创建一个指令/组件来填充其中几个属性,我想知道在 $$watchers 方面将整个表单/配置对象或这些属性单独作为绑定传递是否更有效。 In other words:换句话说:

<my-directive config="config"></my-directive>

versus相对

<my-directive
    prop-one="config.prop1"
    prop-two="config.prop2"
    prop-three="config.prop3">
</my-directive>

Thanks!谢谢!

This is what i think you should do:这是我认为你应该做的:

<my-directive config="config"></my-directive>

and in the directive template you should set two-way binding with ng-module or just one way binding.并且在指令模板中,您应该使用 ng-module 设置双向绑定或仅设置单向绑定。

The purpose of the directive is to unite the logic to one place with is gui and then to expose the result has a config object or using a callback function.该指令的目的是将逻辑与 is gui 统一到一个地方,然后将结果公开给一个配置对象或使用回调函数。

Hope it helps.希望能帮助到你。

Keep in mind that you can't two-way bind an object you can only bind a property.请记住,您不能双向绑定一个对象,而只能绑定一个属性。

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

相关问题 合并日期最有效的方法是什么? - What's the most efficient way to combine dates? 用于构建动态 HTML 的最合适的 Angular 组件/指令/管道是什么? - What is the most appropriate Angular component/directive/pipe to use to build dynamic HTML like this? 在Angular js应用程序中实现甘特图的最有效方法是什么? - What is a most efficient way to implement Gantt Chart in Angular js application? 在JavaScript中,将标签转换为链接的最有效方法是什么? - In javascript, what's the most efficient way to I turn tags into links? 隐藏移动版网站内容的最有效方法是什么? - What's the most efficient way to hide content for a mobile version of a site? 什么是在IE8 +中追加元素的最有效方法? - what's the most efficient way to append elements in IE8+? 比较 javascript 中的 2 个元素的最有效方法是什么? - What's the most efficient way to compare 2 elements in javascript? 将数据存储到Firebase中的多个引用的最有效方法是什么? - What's the most efficient way to store data to multiple refs in firebase? 使用JavaScript评估字符串是否是回文符的最有效方法是什么? - What's the most efficient way to evaluate if a string is a palindrome using Javascript? 为网页的动画标头编码的最有效方法是什么? - What's the most efficient way of coding an animated header for a webpage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM