AngularJS显示来自routeProvider的对话框

Taw*_*ani 6 angularjs angularjs-routing angularjs-bootstrap

是否可以[执行一个功能]例如在请求某个路径时从routeProvider打开一个模态对话框窗口?

myApp.config(function($routeProvider) {
    $routeProvider
        .when('/home',
            {
                controller: 'HomeCtrl',
                templateUrl: 'Home/HomeView.html'
            }
        ).when('/profile/:userId/changepwd',
            function(){                
                $dialog.messageBox(title, msg, btns)
                    .open()
                    .then(function(result){
                    alert('dialog closed with result: ' + result);
                });
            }
        ).otherwise({ redirectTo: '/home' });
});
Run Code Online (Sandbox Code Playgroud)

PS:我想取消路线,而是打开一个对话框.打开对话框不是唯一的问题.取消路线是主要问题.

Ris*_*hal 4

您可以将您的函数作为解析中的依赖项传递,它将等到依赖项解决,当您的对话框结束时,然后使用$location根据需要更改路线并修改历史记录

var app = angular.module('myApp', [])
  .config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/view1', {
       template: '&nbsp',
       controller: //empty function,
       resolve: {
         data1 : function($dialog, $location) {
                     var promise = $dialog.messageBox(title, msg, btns)
                            .open()
                            .then(function(result){
                               alert('dialog closed with result: ' + result);
                               //Use [$location][1] to change the browser history
                            });
                     return promise;
                }
       }
   });
}]);
Run Code Online (Sandbox Code Playgroud)