AngularJS ui-bootstrap打开模态窗口而不改变url

AngularJS ui-bootstrap open modal window without changing the url

本文关键字:改变 url 窗口 模态 ui-bootstrap AngularJS      更新时间:2023-09-26

我在AngularJS项目中使用ui-bootstrap模块。在我打开模式之前,url看起来像这样:localhost:58890/#/Project/46。打开它的代码在这里:

$modal.open(modalServices.newItemModal).result.then(function (name) {
                    var folder = new Item({
                        id: null,
                        projectId: ProjectService.project.ID,
                        name: name,
                        type: ItemType["Folder"],
                        contents : null
                    });

modalServices。newItemModal设置在这里:

var newItemModal = {
    templateUrl: '/template/modal/newItem',
    controller: 'NewItemController',
    backdrop: 'static',
    size : 'sm'
};

后面的代码行$modal。打开url更改为:localhost:58890/是否有可能防止这种情况,并使模态行为像在jQuery模态,它不改变url ?

如果你从锚标记调用你的模态打开函数,不要!

在视图中定义一个按钮,在on-click事件中,像这样触发open modal函数:

    <button ng-click="openmodal()">OPEN MODAL</button>
    app.controller('YourCtrl',function($scope,$modal){
    $scope.openmodal=function(){
        $modal.open(modalServices.newItemModal).result.then(function (name) {
                var folder = new Item({
                    id: null,
                    projectId: ProjectService.project.ID,
                    name: name,
                    type: ItemType["Folder"],
                    contents : null
                });
        }
       });