简体   繁体   English

Angular2 / Nativescript:使用RestService时非常奇怪/无益的错误

[英]Angular2/Nativescript: very strange/unhelpful error when using a RestService

I am busy working on a very basic barcode scanner app. 我正在忙于一个非常基本的条形码扫描器应用程序。 There are two options: enter the barcode or scan the barcode. 有两个选项:输入条形码或扫描条形码。 When I enter the barcode I get the following error: This error doesn't help me at all... Any idea what the cause of this might be/what I can look at? 当我输入条形码时,出现以下错误:此错误根本对我没有帮助...知道这可能是什么原因/我可以看什么?

my error: 我的错误:

JS: EXCEPTION: Uncaught (in promise): TypeError: Cannot read property 'getCookie' of null
JS: ORIGINAL STACKTRACE:
JS: Error: Uncaught (in promise): TypeError: Cannot read property 'getCookie' of null
JS:     at resolvePromise (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:416:31)
JS:     at /data/data/org.nativescript.barcodescanner/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:452:17
JS:     at ZoneDelegate.invokeTask (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:223:37)
JS:     at Object.inner.inner.fork.onInvokeTask (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/core/bundles/core.umd.js:6197:41)
JS:     at ZoneDelegate.invokeTask (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:222:42)
JS:     at Zone.runTask (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:123:47)
JS:     at drainMicroTaskQueue (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:355:35)
JS: Unhandled Promise rejection: Cannot read property 'getCookie' of null ; Zone: angular ; Task: Promise.then ; Value: TypeError: Cannot read property 'getCookie' of null TypeError: Cannot read property 'getCookie' of null
JS:     at CookieXSRFStrategy.configureRequest (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/http/bundles/http.umd.js:1183:91)
JS:     at XHRBackend.createConnection (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/http/bundles/http.umd.js:1223:32)
JS:     at httpRequest (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/http/bundles/http.umd.js:1561:24)
JS:     at Http.request (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/http/bundles/http.umd.js:1661:38)
JS:     at Http.get (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/http/bundles/http.umd.js:1672:25)
JS:     at RestService.getProduct (/data/data/org.nativescript.barcodescanner/files/app/services/rest.service.js:18:26)
JS:     at AppComponent.submitBarcode (/data/data/org.nativescript.barcodescanner/files/app/app.component.js:22:26)
JS:     at /data/data/org.nativescript.barcodescanner/files/app/app.component.js:42:19
JS:     at ZoneDelegate.invoke (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:190:28)
JS:     at Object.inner.inner.fork.onInvoke (/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/core/bundles/core.umd.js:6206:41)
JS: Error: Uncaught (in promise): TypeError: Cannot read property 'getCookie' of null

my app.module.ts: 我的app.module.ts:

import { NgModule, ValueProvider } from "@angular/core";
import { NativeScriptFormsModule } from "nativescript-angular/forms";
import { NativeScriptModule } from "nativescript-angular/platform";

import { HttpModule } from '@angular/http';

import { BarcodeScanner } from "nativescript-barcodescanner";
import { RestService } from './services/rest.service';

import { AppComponent } from "./app.component";






@NgModule({
    imports : [
    NativeScriptModule,     
    NativeScriptFormsModule, 
    HttpModule
    ],
    declarations : [
    AppComponent    
    ],
    providers : [
    RestService,
    BarcodeScanner],
    bootstrap : [AppComponent]      
})
export class AppModule {}

my app.component.ts: 我的app.component.ts:

import { Component, Input, OnInit, Inject } from "@angular/core";
import { BarcodeScanner } from "nativescript-barcodescanner";
import { ProductModel } from './models/product';

import { RestService } from './services/rest.service';



@Component({
    selector: "my-app",
    templateUrl : "./app.component.html"
})
export class AppComponent implements OnInit {
    public barcode: number;
    public textBarcode: number;
    @Input() product: ProductModel;


    public constructor(private restService: RestService, private barcodeScanner: BarcodeScanner) {

    }

    submitTextBarcode() {
        this.restService.getProduct(this.textBarcode)
    .subscribe(
    (res) => {
        this.product = new ProductModel(res.BaseURI, res.CustomError, res.ProviderName, res.RequestFormData, res.RequestURI, res.ResponseCode, res.AvgQty1, res.AvgQty2, res.AvgQty3, res.BarCode, res.Description, res.POSDescription, res.POSPrice, res.ProductCode, res.PurchCount, res.StockOnHand);    },
    (res) => {
        console.log("failure" + res);
    }
    );  
    }


    submitBarcode(barcode: number){ 
    this.restService.getProduct(barcode)
    .subscribe(
    (res) => {
        this.product = new ProductModel(res.BaseURI, res.CustomError, res.ProviderName, res.RequestFormData, res.RequestURI, res.ResponseCode, res.AvgQty1, res.AvgQty2, res.AvgQty3, res.BarCode, res.Description, res.POSDescription, res.POSPrice, res.ProductCode, res.PurchCount, res.StockOnHand);
        //console.log("returned product description: " + this.product.Description);
        //console.log(res);
    },
    (res) => {
        console.log("failure" + res);
    }
    );
    //console.log("product: " + product);

}


    public scan() {
        this.barcodeScanner.scan({
            formats : "EAN_13",
            cancelLabel : "Stop scanning",
            message : "Go scan something Use the volume buttons to turn on the flash",
            preferFrontCamera : false,
            showFlipCameraButton : false
        }).then((result) => {
            this.barcode = +result.text;
            this.submitBarcode(this.barcode);           
        }, (errorMessage) => {
            console.log("Error no scan" + errorMessage);
        });
    }

    public ngOnInit() {     

    }

}

my app.component.html: 我的app.component.html:

<stackLayout>
<label text="Scan or enter a barcode"></label>
<textField hint="Enter barcode" keyboardType="number" [(ngModel)]="textBarcode"></textField>
<button *ngIf="textBarcode" text="Submit" (tap)="submitTextBarcode()"></button> 
<button text="Scan" (tap)="scan()"></button>

<label *ngIf="product" text="Description"></label>
<label *ngIf="product" [text]="product.Description"></label>

<label *ngIf="product" text="POS Description"></label>
<label *ngIf="product" [text]="product.POSDescription"></label>

<label *ngIf="product" text="POS price"></label>
<label *ngIf="product" [text]="product.POSPrice"></label>

<label *ngIf="product" text="Stock On Hand"></label>
<label *ngIf="product" text="product.StockOnHand"></label>

</stackLayout>

Бased on the sample-Groceries tutorial .. notice this line 示例食品杂货店教程上 ..注意此行

import { NativeScriptHttpModule } from "nativescript-angular/http"; 

and the imports ni the same file for NativeScriptHttpModule ..also in the same section the following explanation : 并为ni导入了与NativeScriptHttpModule ..相同的文件,并且在同一部分中进行了以下解释:

"... .NativeScriptHttpModule is a NativeScript wrapper of Angular's HttpModule, a module that declares all of Angular's HTTP-based services—including the Http service that UserService uses..." “ ... .NativeScriptHttpModule是Angular的HttpModule的NativeScript包装,该模块声明了Angular的所有基于HTTP的服务-包括UserService使用的Http服务...”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular2 / Nativescript:尝试构建/运行任何项目时出现奇怪的模糊错误 - Angular2/Nativescript: Strange vague error when trying to build/run Any project Angular2:使用ngSubmit将字符串传递给函数时,非常奇怪/突然的问题 - Angular2: Very strange/sudden issue when using ngSubmit to pass a String to a function nativescript和angular2-没有提供程序错误 - nativescript and angular2 - no Provider Error nativescript angular2相机错误 - nativescript angular2 camera error Angular2 / Nativescript:使用Nativescript核心深色主题时,默认文本颜色存在问题 - Angular2/Nativescript: Issues with default text color when using the Nativescript core dark theme Angular2:尝试使用Rest服务从服务器获取Json时出现奇怪的模糊错误 - Angular2: strange vague error when trying to get Json from server using a rest service 奇怪的NativeScript / Angular2问题,应用程序在错误的位置查找模板 - Strange NativeScript/Angular2 issue, app looks for templates in the wrong location 使用HttpClient时出现Angular错误的Nativescript - Nativescript with Angular error when using HttpClient Angular2:使用Angular-HTTP标头可以正常工作的angular-http RequestOptions时,出现非常模糊的错误 - Angular2: Very vague error when using angular-http RequestOptions where Angular-http Headers works fine 在 Angular2 或 NativeScript 中使用 Typescript 2 &quot;noUnusedLocals&quot; - Using Typescript 2 "noUnusedLocals" with Angular2 or NativeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM