I want to give users the flexibility to customize the format of an address according to their preference.
To achieve this, there will be a text input where users can enter both keywords and regular text.
The goal is to detect when a keyword is entered, extract it from an object, and display it accordingly.
Here is the object structure:
$scope.address = {
"addressline1": "Street Name",
"addressline2": "City and County",
"addressline3": "12",
"country": "United Kingdom",
"postcode": "XE12 2CV"
}
This is the HTML markup:
<input ng-model='value' placeholder="Enter Address Keywords" type="text" />
The directive should accept any input in the text field - however - when a key word is entered as the 'value', the script should retrieve that from the address object and display it.
I am facing challenges in implementing this functionality.
Below is the JavaScript code snippet:
(function() {
'use strict';
angular.module('testApp', [])
.controller('testController', hotelController)
function hotelController($scope, $http) {
var vm = this;
$scope.address = {
"addressline1": "Street Name",
"addressline2": "City and County",
"addressline3": "12",
"country": "United Kingdom",
"postcode": "XE12 2CV"
}
var regexMobile = /addressline[0-9]*$/;
var match = regexMobile.exec($scope.address);
var result = '';
var startPoint = 1;
if (match !== null) {
for (var i = startPoint; i < match.length; i++) {
if (match[i] !== undefined) {
result = result + match[i];
}
}
$scope.value = result;
}
}
})()
Any assistance would be greatly appreciated.