0

app.js

 $stateProvider.state('tenant.propertyGoogleMap', {
            url: '/PropertyGoogleMap',
            templateUrl: '~/App/tenant/views/propertymanagement/propertyGoogleMap.cshtml',
            menu: 'PropertyGoogleMap.Tenant'
        });

html

<button type="button" class="btn btn-primary" ng-click="vm.propertyGoogleMap()">
                    @L("PfMap")
                </button>

js

 vm.propertyGoogleMap = function () {
                $window.open('tenant.propertyGoogleMap', '_blank');
            };

Could you tell me how to combine both $window and $stateProvider to open a new browser tab when user clicks the button ? When I try as shown above then it gives 404 error.Thanks.

Sampath
  • 63,341
  • 64
  • 307
  • 441
  • It cannot work because window.open() takes in input an URL not a uiRouter state name. The method does not know anything about uiRouter and uiRouter states. – Andrea Mar 24 '16 at 15:07
  • @Andrea OK then could you tell me how to do this task ? Thanks. – Sampath Mar 24 '16 at 15:08
  • @Sampath I think [this answer](http://stackoverflow.com/a/30221248/2435473) would help you to redirect to external domain from ui-router context – Pankaj Parkar Mar 24 '16 at 15:40

1 Answers1

1

try with:

vm.propertyGoogleMap = function () {
                    var url = $state.href('tenant.propertyGoogleMap', {}, {absolute: true});
                    $window.open(url, '_blank');
                };

Where $state is the uiRouter $state service.

The method href with option absoulte: true returns the absolute URL of the given state.

Andrea
  • 3,370
  • 1
  • 17
  • 25
  • Having an issue.That is, url should be like this `http://localhost:6240/Application#/tenant/PropertyGoogleMap` but when I use your above solution its like this `http://localhost:6240/#/tenant/PropertyGoogleMap` and due to that, the desired page is not being loaded. Do you know why ? Thanks. – Sampath Mar 24 '16 at 15:47
  • Never mind when I use the `absolute: false` then it works fine.Thanks a lot :) – Sampath Mar 24 '16 at 16:02