2017-03-12 79 views
0

我正在做一個離子應用程序,我想在系統瀏覽器中打開url,我已經安裝了離子inappbrowser插件,但我不知道如何使用它可以幫助我一些代碼。如何使用inappbrowser在離子應用程序中打開URL?

我想在瀏覽器中打開{{object.url}}。

我使用離子1

HTML

<body ng-app="newsapp" ng-controller="newscontroller"> 

<ion-pane> 
    <ion-header-bar class="bar-stable"> 
    <h1 class="title">Tech Crunch</h1> 
    </ion-header-bar> 
    <ion-content> 
    <section class="list"> 

    <article ng-repeat="object in news"> 
    <a navigate-To="{{object.url}}" class="item item-thumbnail-center"> 
     <img ng-src="{{object.urlToImage}}" height="100%" width="100%"> 
    <h2 class="nowhitespace">{{object.title}}/</h2> 
    <p class="nowhitespace">{{object.description}}</p> 
    <h6><i>Published At</i> {{object.publishedAt}}</h6> 

    </a> 

    </article> 

    </section> 
    <ion-infinite-scroll on-infinite="loadMore()" distance="1%"> 
    </ion-infinite-scroll> 

     </ion-content> 
    </ion-pane>u 
    </body> 

app.js

var app = angular.module('newsapp', ['ionic']); 

    .directive("navigateTo",function($ionicGesture){ 

return{ 
restrict: 'A', 
link:function($scope,$element,$attr){ 

var tapharndle = function(e){ 
    var inAppBrowser = window.open{encodeURI{$attr.navigateTo},'_blank','location=yes','toolbar=yes'}; 
}; 
var tapGesture = $ionicGesture.on{'tap',tapharndle,$element}; 

    } 
    } 
    }) 

    $http({ 
     method: "GET", 
     url: "https://newsapi.org/v1/articles?source=techcrunch& 
     sortBy=latest& ``apiKey=90b77760d33d4c76af4c6c53862c9e72" 
     }) .then(function(newsdata){ 
     angular.forEach(newsdata.data.articles, function(newsarticle) { 
    $scope.news.push(newsarticle); 

    }); 
    $scope.lastarticleID= newsdata.data.lastID; 
    //$scope.news =newsdata.data.articles; 
    console.log(newsdata); 
    }) 

}); 

回答

0

您可以使用最新的$cordovaInAppBrowser插件,它提供了Web瀏覽器查看。它可以用來打開圖像,訪問網頁,並打開PDF文件。

使用cordova plugin add cordova-plugin-inappbrowser命令從控制檯添加插件。

位置設置URL的可見性的配置如下:提供給定的URL的網頁上

var defaultOptions = { 
    location: 'no', 
    clearcache: 'no', 
    toolbar: 'no' 
    }; 

進一步的說明。

+0

我不明白它可以解釋 –

+0

我只需要在我的JS添加此代碼..? –

+0

穆罕默德我不明白,這就是爲什麼我在這裏問你 –

相關問題