1

Below is my code:

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'
        });
    }
}
]);

I am opening a Popup for add new lookup and then reloading the page to see the changes. But the problem is : $location.path('url'); is not working.

Usman Khalid
  • 3,032
  • 9
  • 41
  • 66

1 Answers1

0

You should use $state service in that case. Try

$state.go('/edit-lookup/' + $routeParams.lookupMasterId);

Don't forget to inject $state in your controller initilization. Plus in your module definition you need to pass 'ui.router' as a dependency :

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

EDIT

I think you didn't load ui-router.min in your web page. Please load it just after angular.js

<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>
Vineet
  • 4,525
  • 3
  • 23
  • 42