Search code examples
javascriptangularjsgoogle-chromepopupwindow

$location.path does not work in popup browser window


In my JavaScript Addin for Excel, I use window.open("https://localhost:3000/#/posts/editor/", "popup", "width=1000, height=1100") to popup a browser window.

I realise that, unlike a normal browser, we can NOT modify manually the URL in this popup browser window.

This page is built by angularjs, I have a save button in this page, it is linked to the following function:

$scope.save = function () {
    posts.create({ title: "newCreated", link: "" })
        .success(function (post) {
            $location.path("/posts/editor/" + post._id)
        })
})

I realise that $location.path does NOT redirect the page in this popup window. Whereas, in a normal browser, $location.path works.

Does anyone know if it is possible to unlock the popup browser window so that $location.path work?


Solution

  • Try $rootScope.$apply or $scope.$apply()

    $scope.save = function () {
        posts.create({ title: "newCreated", link: "" })
            .success(function (post) {
               $rootScope.$apply(function() {
                $location.path("/posts/editor/" + post._id)
                console.log($location.path());
              });
            })
    })