1

I have a list that looks like this:

Store 1
  Section A
  Section B
  and so on...
Store 2
  Section A
  and so on...

So I open a modal window to create a new store. I return the store when I close the window, and so far that's working great!

<div ng-repeat="store in global.user.company2.store">

I need to push the callback store to $scope.global.user.company2.store[?]

modalInstance.result.then(function (newStore) {
    // How do I get the IndexOf value of store?
    // This is one of the stores in the ng-repeat 
    $scope.global.user.company2.store[???].section.push(newStore)
}, function () {
    $log.info('Modal dismissed at: ' + new Date());
});

The way I'm sending a selected store into the modal is with resolve

    $scope.createSection = function (size) {

        var modalInstance = $modal.open({
            templateUrl: 'createSection.html',
            controller: 'SectionModal',
            size: size,
            resolve: {
                items: function () {
                    // $scope.radio.model === store
                    // $scope.radio.model2 === section
                    return $scope.radio;
                }
            }
        });

UPDATE: Here's a basic plunker http://plnkr.co/edit/UGN4niAO9nQETqhg8lxn The radio model buttons aren't working. If you change resolve items to $scope.radio.model, the modal breaks. So I left it as is. I think maybe it has to do with the btn-radio being part of angular-ui-bootstrap?

6
  • can u make a fiddle? Commented Jan 26, 2015 at 20:25
  • I'll try to make one! Commented Jan 26, 2015 at 20:25
  • please post a plunker, here is an angular template to get you started: plnkr.co/edit/WprgipAdFBtxDKM6jogo?p=info Commented Jan 26, 2015 at 20:26
  • where's the piece that shows how user selects the store it's going to? Just need to put that store object reference into variable something like $scope.currentStore. Then in result would be $scope.currentStore.section.push(newStore) Commented Jan 26, 2015 at 20:44
  • Thanks charlieftl! I have the currently selected store's name. I can display it in the modal. But I don't know the indexof value of it in the array of global.user.store. Right now it just uses radio buttons to select the store. The radio buttons are stores in global.user.stores (ng-repeat). Commented Jan 26, 2015 at 21:14

1 Answer 1

1

When resolving your modal, box your returned object with the array index of the object.
For example:

 $modalInstance.close({ radio: $scope.radio, index: $scope.items.indexOf($scope.radio) } );

Then, when resolving your modal's promise, simply unbox your object:

modalInstance.result.then(function (selectedItem) {
      $scope.selected = selectedItem.radio;
      $scope.selectedIndex = selectedItem.index;
}, function () {});

See the Angular-Bootstrap docs for more details.

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.