nc45 nc45 - 2 years ago 91
AngularJS Question

Change between variables based on selection

so I have two displays/outputs. [A] and [B]. I also have a bunch of functions in a controller that currently just effects [A] through a numpad. I'm trying to create a function that changes what the numpad effects. IE, if [A] is selected, numpad will effect [A]; and if [B] is selected, the numpad will no longer effect [A] but instead effect [B].

Here's what I have:

<div ng-class="{selected:vm.selectedInput==='A'}" ng-click="vm.selectInput('A')">{{vm.A}}</div>
<div ng-class="{selected:vm.selectedInput==='B'}" ng-click="vm.selectInput('B')">{{vm.B}}</div>

.controller('selController', function($scope) {

var vm = this;
vm.selectedInput = 'A';
vm.selectedOutput = vm.A;

vm.selectInput = function(input) {
vm.selectedInput = input;
switch(input) {
case 'A':
vm.selectedOutput = vm.A;
case 'B':
vm.selectedOutput = vm.B;

And then some functions after that which then will effect vm.selectedOutput, which in theory should change between vm.A and vm.B based on what div is selected.

Sample function which doesn't work:

vm.clear= function () {
vm.selectedOutput = '0';

Answer Source

I was able to solve my issue by creating a data object for my variables. = {
    A: {
      name: 'A',
      value: '5'
    B: {
      name: 'B',
      value: '6'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download