Title: Using Standalone Components · Issue #142 · NativeScript/angular · GitHub
Open Graph Title: Using Standalone Components · Issue #142 · NativeScript/angular
X Title: Using Standalone Components · Issue #142 · NativeScript/angular
Description: Is your feature request related to a problem? Please describe. According to the Issues list, it should theoretically be possible to create a NativeScript Angular application that contains standalone components; however, I have yet to fig...
Open Graph Description: Is your feature request related to a problem? Please describe. According to the Issues list, it should theoretically be possible to create a NativeScript Angular application that contains standalon...
X Description: Is your feature request related to a problem? Please describe. According to the Issues list, it should theoretically be possible to create a NativeScript Angular application that contains standalon...
Opengraph URL: https://github.com/NativeScript/angular/issues/142
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using Standalone Components","articleBody":"**Is your feature request related to a problem? Please describe.**\r\n\u003c!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]. --\u003e \r\n\r\nAccording to the Issues list, it should theoretically be possible to create a NativeScript Angular application that contains standalone components; however, I have yet to figure out how to do that without crashing the application. \r\n\r\nIf you look at the application that is generated using `ng new` today, everything is standalone, from the `main.ts` down. It seems that currently `@nativescript/angular` only supports bootstrapping a module, as opposed to an application/component. If I want my main app component to be a standalone component, I can import it into the `AppModule`:\r\n\r\n```ts\r\n@NgModule({\r\n imports: [NativeScriptModule, AppRoutingModule, AppComponent],\r\n bootstrap: [AppComponent],\r\n```\r\n\r\nbut then it creates the compile error `AppComponent class is a standalone component, which can not be used in the @NgModule.bootstrap array. Use the bootstrapApplication function for bootstrap instead.`\r\n\r\nWhen I remove the `bootstrap` option:\r\n\r\n```\r\nThe module AppModule was bootstrapped, but it does not declare '@NgModule.bootstrap' components nor a \"ngDoBootstrap\" method. Please define one of these.\r\n```\r\nThis happens even if I provide an `ngDoBootstrap()` function:\r\n\r\n```ts\r\nexport class AppModule {\r\n ngDoBootstrap() {\r\n console.log('ngDoBootstrap');\r\n }\r\n}\r\n```\r\nOK, so Angular wants an App Module when bootstrapped to have a non-standalone component to bootstrap. Let's try that:\r\n```ts\r\n@Component({\r\n selector: 'ns-root',\r\n template: `\u003cGridLayout\u003e\u003cLabel text=\"hello\"\u003e\u003c/Label\u003e\u003c/GridLayout\u003e`,\r\n})\r\nexport class RootComponent {}\r\n\r\n@NgModule({\r\n imports: [NativeScriptModule, AppRoutingModule],\r\n declarations: [RootComponent],\r\n bootstrap: [RootComponent],\r\n schemas: [NO_ERRORS_SCHEMA],\r\n})\r\nexport class AppModule {}\r\n```\r\nThis works, but as soon as you try to drop in your standalone component:\r\n```ts\r\n@Component({\r\n selector: 'ns-root',\r\n template: `\u003cns-app\u003e\u003c/ns-app\u003e`,\r\n})\r\nexport class RootComponent {}\r\n\r\n@NgModule({\r\n imports: [NativeScriptModule, AppRoutingModule, AppComponent],\r\n declarations: [RootComponent],\r\n bootstrap: [RootComponent],\r\n schemas: [NO_ERRORS_SCHEMA],\r\n})\r\nexport class AppModule {}\r\n```\r\n\r\nYou get a nasty error (at least on my Android Emulator):\r\n\r\n```\r\nSystem.err: An uncaught Exception occurred on \"main\" thread.\r\n System.err: Unable to start activity ComponentInfo{org.nativescript.tracker/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed\r\n System.err: Error: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup\r\n System.err:\r\n System.err: StackTrace:\r\n System.err: setActivityContent(file: src/webpack:/tracker/node_modules/@nativescript/core/ui/frame/callbacks/activity-callbacks.js:234:0)\r\n System.err: at onCreate(file: src/webpack:/tracker/node_modules/@nativescript/core/ui/frame/callbacks/activity-callbacks.js:46:0)\r\n System.err: at onCreate(file: src/webpack:/tracker/node_modules/@nativescript/core/ui/frame/activity.android.js:24:0)\r\n System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4048)\r\n System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4235)\r\n System.err: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:112)\r\n System.err: at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:174)\r\n System.err: at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:109)\r\n System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:81)\r\n System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2636)\r\n System.err: at android.os.Handler.dispatchMessage(Handler.java:107)\r\n System.err: at android.os.Looper.loopOnce(Looper.java:232)\r\n System.err: at android.os.Looper.loop(Looper.java:317)\r\n System.err: at android.app.ActivityThread.main(ActivityThread.java:8705)\r\n System.err: at java.lang.reflect.Method.invoke(Native Method)\r\n System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)\r\n System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)\r\n System.err: Caused by: com.tns.NativeScriptException: Calling js method onCreate failed\r\n System.err: Error: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup\r\n System.err: at com.tns.Runtime.callJSMethodNative(Native Method)\r\n System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1302)\r\n System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:1188)\r\n System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1175)\r\n System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1153)\r\n System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1149)\r\n System.err: at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:57)\r\n System.err: at android.app.Activity.performCreate(Activity.java:9002)\r\n System.err: at android.app.Activity.performCreate(Activity.java:8980)\r\n System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1526)\r\n System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4030)\r\n System.err: ... 13 more\r\n System.err: Caused by: java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup\r\n System.err: at android.view.ViewGroup.addView(ViewGroup.java:5077)\r\n System.err: at android.view.ViewGroup.addView(ViewGroup.java:5057)\r\n System.err: at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:719)\r\n System.err: at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:207)\r\n System.err: ... 24 more\r\n```\r\n\r\n**Describe the solution you'd like**\r\n\r\nA clear and concise example of how to develop a NativeScript Angular app, using standalone components.","author":{"url":"https://github.com/joeskeen","@type":"Person","name":"joeskeen"},"datePublished":"2024-10-30T18:27:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/142/angular/issues/142"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:91ca3795-3dca-408c-7016-4f3b257b21f1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A908:1D1F0B:51AC1:746E4:6A636C10 |
| html-safe-nonce | 1366f50e698467df5b494bbe95fa14b998659ee9ecf02e30090743eb4b904b38 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTA4OjFEMUYwQjo1MUFDMTo3NDZFNDo2QTYzNkMxMCIsInZpc2l0b3JfaWQiOiI4NDIyODAxNzA1MzA3MTcxODU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4b9952d4025641fb5739d11081cacd3bff6a7af15778da4d44f67cb85dd8b1b9 |
| hovercard-subject-tag | issue:2624969043 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/angular/142/issue_layout |
| twitter:image | https://opengraph.githubassets.com/de354f7bc3bb049681cd15f8fb657a244f135b751d0096041ad275ba3824246a/NativeScript/angular/issues/142 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/de354f7bc3bb049681cd15f8fb657a244f135b751d0096041ad275ba3824246a/NativeScript/angular/issues/142 |
| og:image:alt | Is your feature request related to a problem? Please describe. According to the Issues list, it should theoretically be possible to create a NativeScript Angular application that contains standalon... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | joeskeen |
| hostname | github.com |
| expected-hostname | github.com |
| None | e7b5617850fbcd6d10fe2b7c56398444bccb5f3a58a4a18c6d363971295bcd03 |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/angular git https://github.com/NativeScript/angular.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 302428305 |
| octolytics-dimension-repository_nwo | NativeScript/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 302428305 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | aa341b3f432dc63fa9633042725aec601722a352 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width