Kedar
Kedar

Reputation: 35

Angular: How to open angular variable in external browser - appgyver hybrid app

How do I add an angular variable into my controller function? I want to open links in my mobile app in external browser.

This currently works for me:

html:

<button ng-click="openMenu()">Menu</button>

controller.coffee:

.controller("ShowController", ($scope, City, supersonic) ->
    $scope.openMenu = function($scope) {
supersonic.app.openURL(“https://www.google.com“);
};

(The function is in javascript)

However, I need to open my angular variable {{city.menu.url}}, so this is what I placed in the html.

<button ng-click="openMenu(city.menu.url)">Menu</button>

But I don't know how to orient the javascript so that the supersonic.app.openURL opens the variable I specified in the html. Appreciate all answers.

Upvotes: 0

Views: 180

Answers (1)

michelem
michelem

Reputation: 14590

Change this supersonic.app.openURL(“https://www.google.com“);with:

$window.location.href = 'http://www.google.com';

Inject $window in the controller

.controller("ShowController", ($scope, $window, City, supersonic) ->
    $scope.openMenu = function(url) {
        $window.location.href = url; //'http://www.google.com';
    };

Upvotes: 0

Related Questions