1

On updating to tns core module 2.2.0 and angular rc4 (officially released version by telerik), My app can no longer make http calls to a server, I keep getting this error

com.tns.NativeScriptException: 
Calling js method onClick failed

EXCEPTION: Error in /data/data/org.nativescript.EatSafe/files/app/pages/login/login.html:5:75
ORIGINAL EXCEPTION: Error: not implemented
ORIGINAL STACKTRACE:
Error: not implemented
    at NativeScriptDomAdapter.Parse5DomAdapter.getCookie (/data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/platform-server/src/parse5_adapter.js:619:68)
    at CookieXSRFStrategy.configureRequest (/data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/http/src/backends/xhr_backend.js:150:82)
    at XHRBackend.createConnection (/data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/http/src/backends/xhr_backend.js:165:28)
    at httpRequest (/data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/http/src/http.js:22:20)
    at Http.post (/data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/http/src/http.js:78:16)
    at UserService.signin (/data/data/org.nativescript.EatSafe/files/app/shared/services/user.service.js:13:27)
    at LoginComponent.login (/data/data/org.nativescript.EatSafe/files/app/pages/login/login.component.js:31:27)
    at DebugAppView._View_LoginComponent0._handle_tap_8_0 (LoginComponent.template.js:355:28)
    at /data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/core/src/linker/view.js:375:24
    at /data/data/org.nativescript.EatSafe/files/app/tns_modules/nativescript-angular/renderer.js:204:26
ERROR CONTEXT:
[object Object]
File: "/data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/core/src/linker/view.js, line: 365, column: 16

StackTrace: 
    Frame: function:'DebugAppView._rethrowWithContext', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/core/src/linker/view.js', line: 365, column: 17
    Frame: function:'', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/core/src/linker/view.js', line: 378, column: 23
    Frame: function:'', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/nativescript-angular/renderer.js', line: 204, column: 26
    Frame: function:'ZoneDelegate.invoke', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/zone.js/dist/zone-node.js', line: 290, column: 29
    Frame: function:'NgZoneImpl.inner.inner.fork.onInvoke', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/core/src/zone/ng_zone_impl.js', line: 53, column: 41
    Frame: function:'ZoneDelegate.invoke', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/zone.js/dist/zone-node.js', line: 289, column: 35
    Frame: function:'Zone.run', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/zone.js/dist/zone-node.js', line: 183, column: 44
    Frame: function:'NgZoneImpl.runInner', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/core/src/zone/ng_zone_impl.js', line: 84, column: 71
    Frame: function:'NgZone.run', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/@angular/core/src/zone/ng_zone.js', line: 235, column: 66
    Frame: function:'zonedCallback', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/nativescript-angular/renderer.js', line: 203, column: 24
    Frame: function:'Observable.notify', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/data/observable/observable.js', line: 174, column: 23
    Frame: function:'Observable._emit', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/data/observable/observable.js', line: 193, column: 18
    Frame: function:'_android.setOnClickListener.android.view.View.OnClickListener.onClick', file:'/data/data/org.nativescript.EatSafe/files/app/tns_modules/ui/button/button.js', line: 33, column: 32


    at com.tns.Runtime.callJSMethodNative(Native Method)
    at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:862)
    at com.tns.Runtime.callJSMethodImpl(Runtime.java:727)
    at com.tns.Runtime.callJSMethod(Runtime.java:713)
    at com.tns.Runtime.callJSMethod(Runtime.java:694)
    at com.tns.Runtime.callJSMethod(Runtime.java:684)
    at com.tns.gen.android.view.View_OnClickListener.onClick(View_OnClickListener.java:11)
    at android.view.View.performClick(View.java:5233)
    at android.view.View$PerformClick.run(View.java:21209)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:152)
    at android.app.ActivityThread.main(ActivityThread.java:5507)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I have been trying to look online for a release log of the update to see if there are any breaking changes, but to no avail. does anyone have any pointers on how to make http calls with the new nativescript angular updates?

Thank you

4
  • 1
    I do not know if this will actually solve your problem but there is an open issue here on github: github.com/NativeScript/nativescript-angular/issues/397 Commented Aug 18, 2016 at 9:03
  • Thank you, I found the issue and used the suggestion by Nathan and it worked. You have to bootstrap NS_HTTP_PROVIDERS in main.ts, and make sure you set the version of nativescript-angular to 'next' in both package.json files. npm install and build. that should fix it. Commented Aug 18, 2016 at 11:06
  • Which is the "other" package.json file? The one in the app folder? Commented Aug 18, 2016 at 13:02
  • yes, the one in the app folder Commented Aug 18, 2016 at 14:39

2 Answers 2

2

I got this fixed by importing in app.moudle.ts the following

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

And then

 imports: [NativeScriptHttpModule]
Sign up to request clarification or add additional context in comments.

Comments

1

You need this code in your main.ts file

import {Parse5DomAdapter} from '@angular/platform-server/src/parse5_adapter';

(<any>Parse5DomAdapter).prototype.getCookie = function (name) { return null; };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.