I am trying to pass a value to a custom component
below a form that is poplated from a service I put this code to call a custom component
<fields [farmernameid]="farmername.id"></fields>
it should pass the id to the field component so that the component can ask the service for a list of fields that the farmer has. but nothing gets passed, if I remove the [] the string farmername.id gets passed, so to verify I put {{farmername.id}}
in the form above the call to the component, that populates with the id of the selected farmer correctly.
so I guess I am not passing the value correctly.
in the fields.ts I have
export class FieldsComponent {
@Input('farmernameid') farmerToView;
farmer : string;
fieldnames: any;
constructor(private navCtrl: NavController,
private navParams: NavParams,
private jobService: JobService
) {
this.farmer = this.farmerToView;
// sample data until I get the farmer id to pass then will call a service to get the data
this.fieldnames = [
{
"id": "####",
"companyid": "2",
"description": "Behind house",
"fieldacres": 160,
"latitude": "#######",
"longitude": "",
"farmerid": "####"
},
{
"id": "####",
"companyid": "2",
"description": "Testfield",
"fieldacres": 120,
"latitude": "######",
"longitude": "",
"farmerid": "####"
},
{
"id": "####",
"companyid": "2",
"description": "North of shed",
"fieldacres": 80,
"latitude": "######",
"longitude": "",
"farmerid": "####"
}
];
}
}
and in the fields.html is
<ion-list color="light">
<ion-list-header>
Fields for {{farmer}}
</ion-list-header>
<ion-item *ngFor="let fieldname of fieldnames">
<div>{{fieldname.description}}</div>
<div end> {{fieldname.fieldacres}} </div>
<div>{{fieldname.latitude}}</div>
</ion-item>
</ion-list>
“Fields for” shows up from the html template but never {{farmer}} which it should be the id. So I am sure I missed something, I just don’t know what to look for.