Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $location.path同一url不起作用_Javascript_Jquery_Angularjs_Redirect - Fatal编程技术网

Javascript $location.path同一url不起作用

Javascript $location.path同一url不起作用,javascript,jquery,angularjs,redirect,Javascript,Jquery,Angularjs,Redirect,下面是我的代码: app.controller('lookupMasterController', [ '$scope', '$routeParams', '$location', '$modal', 'lookupService', function ($scope, $routeParams, $location, $modal, lookupService) { $scope.openCreatePopup = function () { var modalIn

下面是我的代码:

app.controller('lookupMasterController', [
    '$scope', '$routeParams', '$location', '$modal', 'lookupService', function ($scope, $routeParams, $location, $modal, lookupService) {

$scope.openCreatePopup = function () {

        var modalInstance = $modal.open({
            animation: true,
            templateUrl: 'app/popups/add-lookup.html',
            controller: function ($scope, $modalInstance, $location, $routeParams, lookupService) {
                $scope.cancel = function () {
                    $modalInstance.close();
                }

                $scope.addLookup = function () {
                    $scope.lookup.lookUpConfigId = $routeParams.lookupMasterId;
                    lookupService.save($scope.lookup).$promise.then(
                        function (value) {
                            $location.path('/edit-lookup/' + $routeParams.lookupMasterId);
                        $scope.$apply();// Even this is not working.
                        // Tried the below as well:
                        //$scope.$apply(function () {
                          //      $location.path('/edit-lookup/' + //$routeParams.lookupMasterId);
                           // });

                            $modalInstance.close();
                        },
                    function (error) { /*Do something with error*/
                        alert(error.message);
                    });
                }
            },
            size: 'lg'
        });
    }
}
]);

我打开一个弹出窗口添加新的查找,然后重新加载页面以查看更改。但问题是:
$location.path('url')不工作

在这种情况下,您应该使用
$state
服务。试一试

$state.go('/edit-lookup/' + $routeParams.lookupMasterId);
不要忘记在控制器初始化中注入
$state
。另外,在模块定义中,您需要将“ui.router”作为依赖项传递:

E.g. angular.module('my_app', ['ui.router'])
编辑

我想你没有在网页中加载
ui router.min
。请在
angular.js

<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>

在这种情况下,您应该使用
$state
服务。试一试

$state.go('/edit-lookup/' + $routeParams.lookupMasterId);
不要忘记在控制器初始化中注入
$state
。另外,在模块定义中,您需要将“ui.router”作为依赖项传递:

E.g. angular.module('my_app', ['ui.router'])
编辑

我想你没有在网页中加载
ui router.min
。请在
angular.js

<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>


使用$route.reload()重新加载当前页面:不工作..使用$route.reload()重新加载当前页面:不工作..这将重新加载整个页面,这不是单页应用程序所需要的。因此,我不想尝试此操作。错误:未知提供程序:$stateProvider我没有在我的应用程序中使用状态。现在它给出了这个错误:无法从状态“”解析“/edit lookup/7”,这将重新加载整个页面,而这不是单页应用程序所需要的。因此,我不想尝试此操作。错误:未知提供程序:$stateProvider我没有在我的应用程序中使用状态。现在它出现了以下错误:无法从状态“”解析“/edit lookup/7”