mobile-angular-ui icon indicating copy to clipboard operation
mobile-angular-ui copied to clipboard

How to open modal from the controller?

Open lchan-jigsaw24 opened this issue 9 years ago • 7 comments

Hi,

I'm trying to open a modal popup from the controller -initially I got this warning:Warning: Attempt to set uninitialized shared state: modal1

then I used SharedState to initialize the modal so the error is no longer showing but the modal is not opening - here is my code snippet:

datacontext.sendEmail(emailArray, selectedNotes).then(function(d) { $scope.noteDialogMessage = d; console.log($scope.noteDialogMessage) }, function(error) { $scope.noteDialogMessage = error;

            }).then(function () {
                SharedState.initialize($scope, 'modal1');
                SharedState.turnOn('modal1');
           // $scope.Ui.turnOn('modal1');
        });

I tried a combination of $scope and $rootScope and as you can see I tried $scope.Ui.turnOn and also SharedState.turnOn but nothing is working! Please help!!

thanks

lchan-jigsaw24 avatar May 11 '15 00:05 lchan-jigsaw24

Do you inject SharedState? And i think it's better to init at the controller's scope ,not in local

app.controller('ListController', function ($scope, .....,SharedState) { ... });

nail2008 avatar May 21 '15 09:05 nail2008

have you tried adding a click function to your controller? ui-turn-on="modal1" ng-click="clickModal(1)" $scope.clickModal = function( param ) { ... }

flashdave1973 avatar May 26 '15 21:05 flashdave1973

Hi @nail2008 Yes I am injecting SharedState (otherwise, it wouldn't be available) @flashdave1973 , I need to call the modal after my ajax call so can't do it from a click event Thanks

lchan-jigsaw24 avatar May 27 '15 09:05 lchan-jigsaw24

I was able to get this to work $rootScope.Ui.turnOn('modal1'); you can also try $rootScope.Ui.toggle('modal1');

flashdave1973 avatar Jun 01 '15 02:06 flashdave1973

@flashdave1973 it works for me. Thanks so much.

shawdren avatar Dec 22 '15 05:12 shawdren

I tried with timeout and it worked.

app.controller('EventController', function ($scope, $routeParams, $rootScope, $timeout, SharedState) {
$timeout(function (){
        //$rootScope.Ui.turnOn('friends');
        $rootScope.Ui.toggle('friends');
    }, 100);
}

achinthas avatar Jan 23 '16 16:01 achinthas

Hi, I am new to this app but I noticed that if you are working with ui-content-for and ui-yield-to directives then you need to include ui-content-for inside your ng-view tag. Otherwise your view controller can't find the modal1 node. I don't know if that is intended. Example tpl below.

Controller

app.controller('MainController', function($rootScope, $scope, SharedState){

    SharedState.initialize($scope, 'modal1');
    SharedState.turnOn('modal1');

});

index.html, using ui-content-for

...
<div ng-view class="app-view">
    <div ui-content-for="modals">
        <div ng-include="'modal1.html'"></div>
    </div>
</div>
...
<div ui-yield-to="modals"></div>

alternatively you can include the modal markup directly

<ng-view></ng-view>
<div class="modal" ui-if='modal1' ui-state='modal1'>...</div>

RoboSparrow avatar Mar 29 '16 01:03 RoboSparrow