1

I followed this below link : https://codepen.io/templarian/pen/VLKZLB

But here when clicking More Option, I have to get the dynamic populated Names like

var Obj = [{name:"1st Item",taste:"sweet"},{name:"2nd item",taste:"spicy"}];

Replace of "Alert Cost" and "Alert Player Gold".

I tried but I am failed to get in dynamic looping.

0

1 Answer 1

3

You can do like this.... Add this code inside the function inside demo controller.

$scope.arr = [];
  for(let x of [{name:"1st Item",taste:"sweet"},{name:"2nd item",taste:"spicy"}]) {
    let newArr = [];
    newArr.push(x.name);
    newArr.push(function ($itemScope) {
              alert($itemScope.item.cost);
          });
    $scope.arr.push(newArr);
  }

And then replace the old array of Alert Cost" and "Alert Player Gold" with $scope.arr.

$scope.menuOptions = [
      ['Buy', function ($itemScope) {
          $scope.player.gold -= $itemScope.item.cost;
      }],
      null,
      ['Sell', function ($itemScope) {
          $scope.player.gold += $itemScope.item.cost;
      }, function ($itemScope) {
          return $itemScope.item.name.match(/Iron/) == null;
      }],
      null,
      ['More...', $scope.arr]
  ];

Voila, you good to go. Here is working codepen example. Working example https://codepen.io/anon/pen/jGBJMY?editors=1010

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.