I have 4 scope variables
$scope.defined_vars.p_24_device_ssid
$scope.defined_vars.p_50_device_ssid
$scope.defined_vars.g_24_device_ssid
$scope.defined_vars.g_50_device_ssid
I know if I do it like this, I will get it to work.
if(section == 'private'){
if(freq == '2.4'){
var wifiIndex = 'p_24';
var ssid = $scope.defined_vars.p_24_device_ssid;
var passphrase = $scope.defined_vars.p_24_device_passphrase;
}else{
var wifiIndex = 'p_50';
var ssid = $scope.defined_vars.p_50_device_ssid;
var passphrase = $scope.defined_vars.p_50_device_passphrase;
}
}else{
if(freq == '2.4'){
var wifiIndex = 'g_24';
var ssid = $scope.defined_vars.g_24_device_ssid;
var passphrase = $scope.defined_vars.g_24_device_passphrase;
}else{
var wifiIndex = 'g_50';
var ssid = $scope.defined_vars.g_50_device_ssid;
var passphrase = $scope.defined_vars.g_50_device_passphrase;
}
}
var data = {
cpe_mac: $scope.cpe_mac,
vlan: section,
freq:freq,
ssid: ssid,
passphrase: passphrase,
};
But
the goal here is to learn how to set the dynamic variables.
I am trying to set dynamically before making a POST
$scope.updateWiFi = function(section,freq) {
if(section == 'private'){
if(freq == '2.4'){
var wifiIndex = 'p_24';
}else{
var wifiIndex = 'p_50';
}
}else{
if(freq == '2.4'){
var wifiIndex = 'g_24';
}else{
var wifiIndex = 'g_50';
}
}
var data = {
cpe_mac: $scope.cpe_mac,
vlan: section,
freq:freq,
ssid: $scope.defined_vars.wifiIndex + '_device_ssid',
passphrase: $scope.defined_vars.wifiIndex + '_device_passphrase',
};
console.log("PUT Data is " + angular.toJson(data));
$http({
method: 'PUT',
url: '/updateWiFi',
data: angular.toJson(data)
})
.then(function successCallback(response) {
console.log(response);
}, function errorCallback(response) {
console.log("%cError in updateWiFi()", "color: red;");
console.log(response.statusText);
});
};
I kept getting
$scope.defined_vars.wifiIndex + '_device_ssid',
undefined_device_passphrase
How can I resolve this?