# How to get value of model in the component for the element of the model array it is accessing?

**URL:** <https://discuss.emberjs.com/t/how-to-get-value-of-model-in-the-component-for-the-element-of-the-model-array-it-is-accessing/11261>\
**Category:** Uncategorized\
**Created:** [July 30, 2016, 8:47am UTC](https://discuss.emberjs.com/t/how-to-get-value-of-model-in-the-component-for-the-element-of-the-model-array-it-is-accessing/11261 "2016-07-30T08:47:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gjhawar](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gjhawar/32/12445_2.png) [@gjhawar](https://discuss.emberjs.com/u/gjhawar)\
**Post date:** [July 30, 2016, 8:47am UTC](https://discuss.emberjs.com/t/how-to-get-value-of-model-in-the-component-for-the-element-of-the-model-array-it-is-accessing/11261/1 "2016-07-30T08:47:43Z")

</div>

I have a parent component that renders a child component for each element in the model`s array like :

{{#each model.teachers.teacherPayees as |teacherPayee|}} {{#detailed-teacher-info teacherPayee=teacherPayee model=model}}

# Separation
{{/detailed-teacher-info}} {{/if}} {{/each}}

Now the problem is in the detailed-teacher-info component I want to know which elements it is referring to, the model is like

```
  teacher : {
	"name" : "teacher1",
	 "teacherPayees" : [
	     {"age" : 21, id : 1}, 
	     {"age" : 41, id : 2}
	 ]} 

```

So, component1 should be referring to teacherPayees where age is 21.

In my component js when I do

```
	 setup: function() {
let teacherPayees = this.get('teacherPayee'); //Is a store which has age and id as computed property.
console.log(teacherPayees.age); //Is a computed property - How do I get the value for it
console.log(this.get('model.teacher.teacherPayees')); // This has the array but how would I know which element is this component using.
}.on('init')

```

So, the problem is how do I know which model element of the array the current component is referring to.

---

<div class="post-metadata">

**Author:** ![jasonmit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jasonmit/32/182_2.png) [@jasonmit](https://discuss.emberjs.com/u/jasonmit)\
**Post date:** [July 30, 2016, 9:16am UTC](https://discuss.emberjs.com/t/how-to-get-value-of-model-in-the-component-for-the-element-of-the-model-array-it-is-accessing/11261/2 "2016-07-30T09:16:02Z")

</div>

I’m having a hard time understanding the question.

---

<div class="post-metadata">

**Author:** ![gjhawar](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gjhawar/32/12445_2.png) [@gjhawar](https://discuss.emberjs.com/u/gjhawar)\
**Post date:** [July 30, 2016, 7:54pm UTC](https://discuss.emberjs.com/t/how-to-get-value-of-model-in-the-component-for-the-element-of-the-model-array-it-is-accessing/11261/3 "2016-07-30T19:54:27Z")

</div>

So basically I have an array in the model called teacherPayees and for each element in the array I am rendering a form with the fields age and id correct.

Now in that child component i.e. detailed-teacher-info I want to access all the values of the model on init which is what my setup function is doing. The question is how do I do that? I am able to get the whole array in the js file by doing this this.get(‘model.teacher.teacherPayees’) but I just want the value of teacherPayees array that the current component is rendering.

---

<div class="post-metadata">

**Author:** ![jasonmit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jasonmit/32/182_2.png) [@jasonmit](https://discuss.emberjs.com/u/jasonmit)\
**Post date:** [July 31, 2016, 4:00am UTC](https://discuss.emberjs.com/t/how-to-get-value-of-model-in-the-component-for-the-element-of-the-model-array-it-is-accessing/11261/4 "2016-07-31T04:00:51Z")

</div>

> [@gjhawar](#):
>
> Now in that child component i.e. detailed-teacher-info I want to access all the values of the model on init which is what my setup function is doing.

So it sounds like you’re describing something like this:

```hbs
{{#each teacherPayees as |teacherPayee|}}
  {{x-component teacherPayee=teacherPayee teacherPayees=teacherPayees}}
{{/each}}

```

Components will not have the attributes in the `init` lifecycle hook. You likely want to start accessing attributes via `didReceiveAttrs`.
