Search code examples
nativescriptangular2-nativescript

Cannot access native api (iOS or Android) using NativeScript + Angular-2 project


How to replicate:

tns create Something --ng
cd Something

now following this link https://docs.nativescript.org/angular/core-concepts/accessing-native-apis-with-javascript.html

npm install tns-platform-declarations --save-dev

replaced contents of tsconfig.json and reference.d.ts

tns run iOS

I'm getting

file:///app/tns_modules/@angular/compiler/bundles/compiler.umd.js:18646:26: JS ERROR Error: Can't resolve all parameters for ItemsComponent: (?).

ts version 2.1.6
xcode version 8.2.1
"tns-platform-declarations": "^2.5.0",
"tns-ios": {"version": "2.5.0"}
"nativescript-angular": "1.4.0",

without those modifications, iOS project runs as intended.

I think its something with references, but I'm not sure.


Solution

  • There are some DOM related types that need to be handled when working in Angular-2 enabled project. This will be dealt with in the next releases of nativescript-dev-typescript but meanwhile, use the following in your references.d.t.s

    // <reference path="./node_modules/tns-core-modules/tns-core-modules.es2016.d.ts" />
    
    /// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
    /// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
    
    declare type Comment = any;
    declare type CloseEvent = any;
    declare type Document = any;
    declare type DocumentFragment = any;
    declare type Element = any;
    declare type History = any;
    declare type HTMLAnchorElement = any;
    declare type HTMLCollection = any;
    declare type HTMLDocument = any;
    declare type HTMLElement = any;
    declare type HTMLInputElement = any;
    declare type HTMLScriptElement = any;
    declare type HTMLStyleElement = any;
    declare type KeyboardEvent = any;
    declare type Location = any;
    declare type MessageEvent = any;
    declare type MouseEvent = any;
    declare type Node = any;
    declare type NodeList = any;
    declare type Text = any;
    declare type WebSocket = any;
    

    Based on this application