首页 文章

无法在angular2 nativescript中读取未定义的属性getPackageManager

提问于
浏览
0

我提到了这个nativescript-appList Plugin . 我收到此运行时错误无法读取未定义的属性 getPackageManager .

我在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”);

1 回答

  • 2

    该插件似乎与Angular项目不兼容,但有一个简单的解决方案可以使它工作 . 为此,您需要直接修改插件的源代码 . 克隆repo并应用下面的更改,然后 npm pack 生成新修改的 tgz 文件或安装插件并直接修改 node_modules/nativescript-applist/Apps.android.js 中的代码(这不是好方法,因为删除node_modules文件夹时将删除所有更改)

    要使插件在Angular中工作,请执行以下操作 - 打开 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
    

    你很高兴去!

相关问题