JavaScript AngularJS display array based off checkbox selection angularjs display array of objects,angularjs display array in html,

I'm not sure what would you like to achieve, but i could code your example like this: http://codepen.io/anon/pen/xGNLJe?editors=101

Explanations:

(function(angular) {
  "use strict";

  angular
    .module('formApp', [])
    .controller('FormController', ['$scope', function($scope) {
      var groupOne = [
        { name: 'BudgetCharts'},
        { name: 'BudgetComparison'},
        { name: 'EDITBudgetAmounts'}
      ];

      var groupTwo = [
        { name: 'Optimize'},
        { name: 'ReviewAndAdjust'}
      ];

      var groupThree = [
        { name: 'Export'},
        { name: 'Import'},
        { name: 'Construction Program'},
        { name: 'ExportStrategies'}
      ];

      $scope.formData = {};

      $scope.$watch("formData.displayOption", function(displayOption) {
        if(displayOption) {
          var value1 = displayOption.fiftyMill,
              value2 = displayOption.hundredMill,
              value3 = displayOption.statusQuo,
              value4 = displayOption.doNothing;

          $scope.pages = null;
          $scope.message = null;

          if (value1 === true || value2 === true) {
            $scope.pages = groupOne;
          } else if (value3 === true) {
            $scope.pages = groupTwo;
          } else if (value1 === true || value2 === true && value3 === true) {
            $scope.pages = groupThree + groupOne + groupTwo;
          } else {
            $scope.message = 'No Options';
          }
        }
      }, true);
    }]);
})(angular);

So, step by step:

  1. Remove ng-click:

As you could see, your checkbox's markup now looks like this:

<input type="checkbox" name="displayOption" ng-model="formData.displayOption.fiftyMill"/>

I removed your ng-click handler and process ng-model updating with $scope.$watch (https://docs.angularjs.org/api/ng/type/$rootScope.Scope) like this:

$scope.$watch("formData.displayOption", function(displayOption) { ... }, true);

  1. Add $scope.pages and $scope.message variables, interact with it in code and display in view. This is body of your $watch function:

This fires every time, when "watching" variable (formData.displayOption in your case) changes.

$scope.pages = null;
$scope.message = null;

if (value1 === true || value2 === true) {
    $scope.pages = groupOne;
} else if (value3 === true) {
    $scope.pages = groupTwo;
} else if (value1 === true || value2 === true && value3 === true) {
    //
    // Algorithm never goes here, because:
    // value1 === true || value2 === true, always goes to first if block
    // value3 === true, it goes to second if block
    // there aren't any other options to go here 
    //
    $scope.pages = groupThree + groupOne + groupTwo;
    //
    // groupThree, groupOne, groupTwo are arrays. If you plus
    // arrays in javascript like this: 
    // [1,2] + [3,4,5] you will get string = "1,23,4,5"
    //
    // if you want to have [1,2,3,4,5] array as result of adding arrays,
    // you have to use concatenation like this:[1,2].concat([3,4,5])
    //
    // In your case:
    // $scope.pages = groupThree.concat(groupOne.concat(groupTwo));
} else {
    $scope.message = 'No Options';
}

and then display in view (as you can see, you assign into $scope.pages an array, so you could iterate over it with ng-repeat):

<h3>Pages</h3>
<div ng-repeat="page in pages">
  {{ page.name }}
</div>  

<div>{{ message }}</div>

P.S. Look at comments in my code, you could have mistakes in places i've commented.

Answer:1

I have a small and quite standard application that: Fetches objects from the server Renders the objects and allows some editing on them. If it is important, this editing only affects DS.hasMany ...

I have a small and quite standard application that: Fetches objects from the server Renders the objects and allows some editing on them. If it is important, this editing only affects DS.hasMany ...

I'm looking for a list of time zones that corresponds to major cities. Like what java.util.TimeZone can provide. I mean, I want to resolve the America/Los_Angeles identifier to UTC-8:00 in javascript. ...

I'm looking for a list of time zones that corresponds to major cities. Like what java.util.TimeZone can provide. I mean, I want to resolve the America/Los_Angeles identifier to UTC-8:00 in javascript. ...

  1. timezones list json

Please look at below codes: Case 1: var a = { b: function(){ console.log(a) }, c:1 }; Case 2: var a = { b:a, c:1 }; Now when I write this : a.b() // for first console....

Please look at below codes: Case 1: var a = { b: function(){ console.log(a) }, c:1 }; Case 2: var a = { b:a, c:1 }; Now when I write this : a.b() // for first console....

  1. javascript object accessing
  2. javascript object accessing properties
  3. javascript object accessing values
  4. javascript accessing object properties with variables
  5. javascript accessing object properties dynamically
  6. javascript accessing object keys
  7. javascript accessing object in array
  8. javascript accessing object properties by index
  9. javascript accessing object fields
  10. javascript accessing object elements
  11. js accessing object properties
  12. js accessing object values
  13. js accessing object
  14. basic javascript accessing object properties with variables
  15. basic javascript accessing object properties with bracket notation
  16. basic javascript accessing object properties with dot notation
  17. basic javascript accessing object properties with variables freecodecamp
  18. basic javascript accessing object properties with dot notation freecodecamp
  19. accessing javascript object variables
  20. accessing javascript object in html

I get this error from the TrackballControls.js: this.domElement.addEventListener is not a function This occurs when I assign the TrackballControls to a DOM: // 'container' is a variable var ...

I get this error from the TrackballControls.js: this.domElement.addEventListener is not a function This occurs when I assign the TrackballControls to a DOM: // 'container' is a variable var ...