Mithun Shreevatsa
Mithun Shreevatsa

Reputation: 3609

Is it good or bad to share big json data in Angular components?

Considering the code below, is it good to share a big json data as an input to test component or make use of service.

vm.data = [{name: 'John'},{name: 'Steve'},...];

<test-component big-data="{{vm.data}}"></test-component>

Which would be the ideal approach using Angular 1.5 and as well as Angular-2 components?

Upvotes: 0

Views: 336

Answers (1)

quirimmo
quirimmo

Reputation: 9988

It seems that you are passing your data through a simple attribute to the component or through @.

In my opinion you should define big-data as binding parameter through <, which allows you to pass angular expressions and then pass the data to the component. It has been introduced exactly in order to avoid the @ when you want to avoid objects conversions.

About passing data in general to the component, if your component manipulates that data, sure you can pass it directly all the data as a binding parameter. There are actually no restrictions about that.

Then if it's better to use a shared service between the component and the app in order to get the data, this is usually depending on the specific use case.

For example, if your component works always with the same type of data, retrieved by always the same request, maybe you can get the data directly inside the component through an embedded service.

But actually the goal of components is to have a reusable code, so usually the approach you are having is a good choice, because your component could be reused providing any kind of data.

Actually the data is out-of-the-box and it's working doesn't depend on the particular data.

I hope this helps.

Upvotes: 1

Related Questions