Help me
I want to save leaflet coordinates.
The input component gets a value, from the confirmation button it has been selected. But when stored the value (coordinates) does not exist.
What is the right way, help me, this makes me want to scream …
.html file
<ion-item>
<ion-label></ion-label>
<ion-input type="text" text-right placeholder="Keterangan tambahan alamat" id="c" [(ngModel)]="postcode"></ion-input>
</ion-item>
<div class="btn-fisx-bottom">
<button ion-button full class="bg-thime btn-round btn-text" (click)="saveAddress()">Simpan Alamat</button>
</div>
/////////////////////////////////////////////////////////////////
.ts file
loadmap() {
var tileLayer = new leaflet.TileLayer(‘http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png’,{
attribution: '© OpenStreetMap ’
});
var map = new leaflet.Map(‘map’, {‘zoom’: 16,
‘layers’: [tileLayer]
})
var marker = null;
map.locate({setView: true,
maxZoom: 18
}).on(‘click’, function (e) {
if (marker !== null) {
map.removeLayer(marker);
}
marker = leaflet.marker(e.latlng).addTo(map);
////////////////////////////////////////
var old = console.log;
var logger = (document.getElementById(‘c’));
console.log = function (message) {
if (typeof message == ‘object’) {
logger.innerHTML = “”;
logger.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : String(message)) + ‘
’;
} else {
logger.innerHTML = “”;
logger.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : String(message)) + ‘
’;
}
}
console.log(e.latlng);
/////////////////////////////////////////
});
}
**saveAddress()** {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if (this.phone.length == 0) {
this.showToast('Belum masukkan nomor telepon');
} else if (this.address_2.length == 0) {
this.showToast('Belum masukkan keterangan tambahan alamat');
} else if (this.postcode.length == 0) {
this.showToast('Enter postcode');
} else {
...
} else {
...
}
}
..
}
}
...
}
}
///////////////////////////////////////////////////////////////////////////////////////////////
**TypeError: Cannot read property 'length' of undefined**
at AddressPage.webpackJsonp.121.saveAddress
(http://localhost:8101/build/main.js:547:40)
at Object.eval [as handleEvent] (ng:///AppModule/AddressPage.ngfactory.js:279:27)
at handleEvent (http://localhost:8101/build/vendor.js:13559:172)
at callWithDebugContext (http://localhost:8101/build/vendor.js:15044:42)
at Object.debugHandleEvent [as handleEvent] (http://localhost:8101/build/vendor.js:14631:12)
at dispatchEvent (http://localhost:8101/build/vendor.js:10008:25)
at http://localhost:8101/build/vendor.js:10622:38
at HTMLButtonElement.<anonymous> (http://localhost:8101/build/vendor.js:36779:53)
at t.invokeTask (http://localhost:8101/build/polyfills.js:3:15660)
at Object.onInvokeTask (http://localhost:8101/build/vendor.js:4924:33)
```