Error creating custom component

plugins

#1

I’m trying to create a custom component that I can include in multiple pages,yet I get an error whenever I try to use it.

So far this is what I have done…

  1. Used nativescript-angular-cli to create a new component, edited the paths to ensure they were correct
  2. Added in custom HTML and code to the component
  3. Made sure the component extends ContentView
  4. Registered the element in main.ts
  5. Imported the component into the app module

However when I include it, I get the following:

TypeError: Object prototype may only be an Object or null: undefined
System.err: File: "<unknown>, line: 1, column: 265
System.err: 
System.err: StackTrace: 
System.err: 	Frame: function:'__extends', file:'file:///data/data/com.gop.premapp/files/app/tns_modules/tslib/tslib.js', line: 64, column: 9
System.err: 	Frame: function:'', file:'file:///data/data/com.gop.premapp/files/app/newsfeed/newsfeed.component.js', line: 21, column: 13
System.err: 	Frame: function:'', file:'file:///data/data/com.gop.premapp/files/app/newsfeed/newsfeed.component.js', line: 146, column: 2
System.err: 	Frame: function:'require', file:'', line: 1, column: 266
System.err: 	Frame: function:'', file:'file:///data/data/com.gop.premapp/files/app/app.module.js', line: 30, column: 28
System.err: 	Frame: function:'require', file:'', line: 1, column: 266
System.err: 	Frame: function:'', file:'file:///data/data/com.gop.premapp/files/app/main.js', line: 6, column: 20
System.err: 	Frame: function:'require', file:'', line: 1, column: 266
System.err: 
System.err: 	at com.tns.Runtime.runModule(Native Method)
System.err: 	at com.tns.Runtime.runModule(Runtime.java:553)
System.err: 	at com.tns.Runtime.run(Runtime.java:545)
System.err: 	at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
System.err: 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
System.err: 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5871)
System.err: 	... 8 more

#2

I guess you are confused between Angular and NativeScript components. If you are creating a Angular component, you will import it in Angular module. If it’s a NativeScript component, you will just register it.

If you can show us some code, we may able to give you some directions.


#3

You are correct, however I solved the solution via advice from Slack!

Thank you though :smiley:


#4

To help others, I didn’t need to register the element or extend ContentView

:man_shrugging: