ERROR TypeError: Cannot read property ‘value’ of undefined.
Please guide.
html file
<ion-title>{{ 'addon.profile.profile' | translate }}</ion-title>
<core-loading [hideUntil]=“loaded”>
<ion-item text-wrap>
<h1>{{'addon.profile.clickfieldtoedit' | translate }}</h1>
</ion-item>
<ion-list>
<ion-item>
<ion-select [(ngModel)]="profilefield.value" interface="action-sheet" >
<ion-option *ngFor="let field of profilefielddata" [value]="field">{{field}}</ion-option>
</ion-select>
</ion-item>
</ion-list>
<core-empty-box *ngIf="profilefielddata.length == 0" icon="stats" [message]="'addon.profile.noprofiledata' | translate"></core-empty-box>
<ion-row>
<ion-col>
<button ion-button padding block (click)="update()"> {{ 'addon.profile.save' | translate }}</button>
</ion-col>
</ion-row>
TS file ----
// (C) Copyright 2015 Moodle Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an “AS IS” BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component } from ‘@angular/core’;
import { IonicPage, NavController, NavParams } from ‘ionic-angular’;
import { AddonModAssignParticipant } from ‘@addon/mod/assign/providers/assign’;
import { CoreSitesProvider } from ‘@providers/sites’;
import { CoreUserProfileFieldDelegate } from ‘@core/user/providers/user-profile-field-delegate’;
import { CoreWSProvider } from ‘@providers/ws’;
import { CoreDomUtilsProvider } from ‘@providers/utils/dom’;
/**
-
Generated class for the AddonProfileChangeYearofhvacexperiencePage page.
-
See UI Components | User Interface Application Building Components for more info on
-
Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: ‘page-addon-profile-change-yearofhvacexperience’,
templateUrl: ‘addon-profile-change-yearofhvacexperience.html’,
})
export class AddonProfileChangeYearofhvacexperiencePage {
settings: any;
user: AddonModAssignParticipant;
profilefield: any = {};
siteUrl: string;
profilefielddata: any = ;
loaded = false;
constructor(public navCtrl: NavController,
public navParams: NavParams,
private sitesProvider: CoreSitesProvider,
protected userProfileFieldDelegate: CoreUserProfileFieldDelegate,
protected wsProvider: CoreWSProvider,
protected domUtils: CoreDomUtilsProvider) {
this.user = navParams.get('user');
const currentSite = sitesProvider.getCurrentSite();
this.siteUrl = currentSite.getURL();
}
ionViewDidLoad(): void {
this.fetchData().finally(() => {
this.profilefield = this.user.customfields.filter((item: any) => {
return item.shortname == 'worker_hvac_exp';
})[0];
//console.log('profilefield:', this.profilefield)
this.loaded = true;
});
}
async fetchData(): Promise {
return this.wsProvider.callAjax('auth_email_get_signup_settings', {}, { siteUrl: this.siteUrl })
.then((result) => {
this.profilefielddata = result.profilefields.filter((item: any) => {
return item.shortname == 'worker_hvac_exp';
})[0]
.param1
.split(/\n/)
.filter((item: any) => {
return item != '--Select an option--';
});
}).catch((error) => {
this.domUtils.showErrorModal(error);
this.navCtrl.pop();
});
}
update(): void {
const siteId = this.sitesProvider.getCurrentSiteId();
this.sitesProvider.getSite(siteId).then((site) => {
const data = {
user: this.user
};
site.write('local_skillcat_update_user', data)
.then(() => {
this.navCtrl.pop();
}).catch((error) => {
this.domUtils.showErrorModal(error);
this.navCtrl.pop();
});
});
}
}