2017-09-27 76 views
0

我提到了nativescript-appList Plugin。我得到這個運行時錯誤無法讀取未定義的屬性getPackageManager無法讀取屬性getPackageManager undefined in angular2 nativescript

我在angular2-nativescript

import * as AppList from "nativescript-applist"; 

// inside the constructor 

console.log("First", "Test"); 

    AppList.getInstalledApps(function(apps) { 

     console.log("Second", "Test"); 

     }, { 
      withIcons: true 
     }); 

在命令提示符下,我無法看到這篇日誌的console.log(「二」,「測試」)的內部構造運行下面的代碼這一點; 。我只能看到這個日誌console.log(「First」,「Test」);

回答

2

該插件似乎與Angular項目不兼容,但有一個簡單的修復方法使其工作。爲了做到這一點,你需要直接修改插件的源代碼。或者克隆回購並應用下面的更改,然後npm pack生成新修改的tgz文件或安裝該插件並直接修改node_modules/nativescript-applist/Apps.android.js中的代碼(這不是一種好方法,因爲刪除node_modules文件夾時將刪除所有更改)

要在角插件工作做follwing - 開放node_modules/nativescript-applist/Apps.android.js - 移動方法中的前兩個延遲加載的特性

var androidApp = app.android; 
var androidAppCtx = androidApp.context; 

function getInstalledListOfApps(callback, cfg) { 
    // more code follows here 

function getInstalledListOfApps(callback, cfg) { 
    var androidApp = app.android; 
    var androidAppCtx = androidApp.context; 

    // more code follows here 

後,你是好去!

+0

感謝您的回答。它沒有奏效,我測試了它。 – Steve

+1

我已經創建了一個測試項目,並且按照我的預期在上面進行了更改 - 您確定要在插件的源文件中進行更改嗎?請記住,爲了使這些更改生效,您需要保留'node_modules文件夾',但刪除'platforms'文件夾並重建項目 –

+0

謝謝你的工作。我刪除了平臺並再次添加。 – Steve

相關問題