alex alex - 4 months ago 17
AngularJS Question

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. 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. 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!

Answer

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.

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.

Hope it helps.

Keep in mind that you can't two-way bind an object you can only bind a property.