【问题标题】:Cannot read property getPackageManager of undefined in angular2 nativescript无法读取 angular2 nativescript 中未定义的属性 getPackageManager
【发布时间】:2017-09-27 05:06:07
【问题描述】:

我提到了这个nativescript-appList Plugin。我收到此运行时错误 Cannot read property getPackageManager of undefined.

我在 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("Second", "Test"); .我只能看到这个日志 console.log("First", "Test");

【问题讨论】:

    标签: angular typescript nativescript angular2-nativescript


    【解决方案1】:

    该插件似乎与 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
    

    你很高兴!

    【讨论】:

    • 感谢您的回答。它不起作用。我测试了它。
    • 我已经创建了一个测试项目,它在我这边按照上面的更改工作 - 你确定你在插件的源文件中进行更改吗?请记住,为了使这些更改生效,您需要保留 node_modules folder 但删除 platforms 文件夹并重建项目
    • 谢谢它按你说的那样工作。我删除了平台并再次添加。
    猜你喜欢
    • 2018-02-09
    • 1970-01-01
    • 2018-08-04
    • 2017-12-15
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    • 2019-08-04
    相关资源
    最近更新 更多