ui-route works weird juste the first time angularjs -
i have problem, first time press button every works fine when close modal , want re-press button(open me) , not work anymore
where problem ?
this route
angular.module('ui.bootstrap.demo').config(function($stateprovider, $urlrouterprovider,$qprovider){ $stateprovider .state("connexion", { url: "/", views: { // column two, we'll define separate controller 'principal': { abstract :true, templateurl: 'connexion.html' } } }) .state('agenda', { url: "/agenda", views: { // column two, we'll define separate controller 'principal': { abstract :true, // templateurl: 'agenda.html' template:'<a ui-sref="view">open me!</a>' } } }) .state('modal', { abstract: true, parent: 'agenda', url: '/modal', onenter: ['$uibmodal', '$state', function($uibmodal, $state) { $uibmodal.open({ animation: true, arialabelledby: 'modal-title', ariadescribedby: 'modal-body', templateurl: 'mymodalcontent.html', controller: 'modalinstancectrl', resolve: { } }) }] }) .state('view', { url: ':id1', parent: 'modal', views: { 'modal@': { template: '<div class="navbar">'+ '<div class="navbar-inner">'+ '<h4 class="brand">quick start</h4>'+ '<ul class="nav">'+ '<li><a ui-sref="foo">route 1</a></li>'+ '<li><a ui-sref="bar">route 2</a></li>'+ '</ul>'+ '</div>'+ '</div>' } } }) .state('foo', { url: ':id2', parent: 'modal', views: { 'modal@': { template: '<h1>foo</h1><a ui-sref="view">back menu</a>' } } }) .state('bar', { url: ':id3', parent: 'modal', views: { 'modal@': { template: '<h1>bar</h1><a ui-sref="view">back menu</a>' } } }) $urlrouterprovider.otherwise("/"); $qprovider.erroronunhandledrejections(false); }) and plunker
http://plnkr.co/edit/4d6fsqv0fipqtjoniebs?p=preview
if can me
thanks in advance
this had 2 issues.
you not having reference controller in modal template. why buttons
ok,canceldon't work! so, usingcontrollerassyntax,$uibmodal.open({ animation: true, arialabelledby: 'modal-title', ariadescribedby: 'modal-body', templateurl: 'mymodalcontent.html', controller: 'modalinstancectrl', controlleras: '$ctrl', resolve: {} })you remaining in same state of
modalafter closing it. fixed following,$ctrl.ok = function() { alert(2) $uibmodalinstance.close(); $state.go("agenda"); }; $ctrl.cancel = function() { $uibmodalinstance.dismiss('cancel'); $state.go("agenda"); };
edit: in order cover kinds of modal close , visit agenda state, can make use of modalinstance.closed.then. this:
var modalinstance = $uibmodal.open({ ... }) modalinstance.closed.then(function() { $state.go("agenda") }) you can remove $state.go $ctrl.ok , cancel buttons.
Comments
Post a Comment