Dynamic links in Ionic, with inAppBrowser

0

I'm developing an app with Ionic, which consumes an external API (json). To make links that open in the native browser, I added the inAppBrowser plugin and it worked.

The question is that some links are dynamic, constructed with API variables, in the case of "url" and "id", as follows:

<button id="encontrar-button1" class="button button-balanced  button-block icon-left ion-plus-circled" onclick="window.open('http://www.site.com/pagina/{{ url }}/{{ id }}/', '_system', 'location=yes'); return false;">Link</button>

It does not work ... it seems to me that the Angular discards the variables. How to solve?

    
asked by anonymous 30.04.2016 / 16:02

1 answer

0

First you can not use onClick directives in this case, otherwise the variables will not be translated by angular. And another, do not use the window object directly on your links. Create a method in your controller for this.

For example, leave it in your html:

<button id="encontrar-button1" ng-click="openURL('http://www.site.com/pagina/{{ url }}/{{ id }}/')" class="button button-balanced  button-block icon-left ion-plus-circled">Link</button>

And in the respective controller create a method like this:

$scope.openURL = function(url){
    window.open(url, '_system', 'location=yes');
}
    
30.04.2016 / 18:04