Nisar Afridi
Nisar Afridi

Reputation: 157

Open Link in Angular based on data from scope

I have user GPS location, these are not fixed, and from frontend i have to open these as google map link.

<a href="#" ng-click='window.open("https://www.google.com/maps/place/{{data.usergps}}", "_system", "location=yes"); return false;'>Open Map</a>

the above give error of Syntax Error: Token 'false', but if i use same with onClick then it will work fine.

another method is to open using a function from controller,

$scope.openMap = function () {
      $scope.data.usermapLink="https://www.google.com/maps/place/33.719910,73.058354"
        $window.open($scope.data.usermapLink);
    };

View:

<a href="#" ng-click="openMap()">Open Map</a>

But problem with this method is that it will open window and my view will be cleared at background, like view data will be cleared, when user press back button.

My Main objective is to open the link based on GPS coordinates from $scope.

Please Advise.

Thanks

Upvotes: 1

Views: 499

Answers (2)

Nisar Afridi
Nisar Afridi

Reputation: 157

I was not adding ng-href

View: <a ng-href="" ng-click="openMap()">Open Map</a> Controller:

$scope.openMap = function () {
        $window.open($scope.data.usermapLink, '_system', 'location = yes');
    };

this will open map link in google map application.

Source: [https://stackoverflow.com/a/32198740/6915298][1]

Thanks

Upvotes: 1

Pritam Banerjee
Pritam Banerjee

Reputation: 18923

You can do like :

 ng-click = "openLink()"

Then in JavaScript:

 $scope.openLink = function(){
     $http.get("your.link.html");
 }

And also don't forget to inject $http in your controller.

Upvotes: 1

Related Questions