angularjs - Open ionicModal on stateChangeStart -
i have been reviewing different methods authorization/authentication in framework. trying assign value state, use ui-routers ability detect state change using $statechangestart. injecting ionicmodal service app.js .run function , creating modal , attaching $rootscope. when try , open following error:
cannot read property 'show' of undefined
here app.js:
angular.module('authlyapp', ['ionic', 'authlyapp.controllers', 'authlyapp.services']) .run(function($ionicplatform, $ionicmodal, $rootscope) { $ionicplatform.ready(function() { if (window.cordova && window.cordova.plugins.keyboard) { cordova.plugins.keyboard.hidekeyboardaccessorybar(true); cordova.plugins.keyboard.disablescroll(true); } if (window.statusbar) { statusbar.styledefault(); } }); $ionicmodal.fromtemplateurl('templates/login.html', { scope: $rootscope }).then(function(modal) { $rootscope.modal = modal; }); $rootscope.$on('$statechangestart', function(event, next, tostate, fromstate, toparams, fromparams){ console.log(next) if ('data' in next && 'requireauth' in next.data) { event.preventdefault(); $rootscope.modal.show(); } }); }) .config(function($stateprovider, $urlrouterprovider) { $stateprovider .state('app', { url: '/app', abstract: true, templateurl: 'templates/menu.html', controller: 'appctrl', data: { requireauth: true } }) .state('app.search', { url: '/search', views: { 'menucontent': { templateurl: 'templates/search.html' } } }) .state('app.browse', { url: '/browse', views: { 'menucontent': { templateurl: 'templates/browse.html' } } }) .state('app.playlists', { url: '/playlists', views: { 'menucontent': { templateurl: 'templates/playlists.html', controller: 'playlistsctrl' } } }) .state('app.single', { url: '/playlists/:playlistid', views: { 'menucontent': { templateurl: 'templates/playlist.html', controller: 'playlistctrl' } } }); $urlrouterprovider.otherwise('/app/playlists'); });
Comments
Post a Comment