NativeScript / plugin-seed

Build NativeScript Plugins Fast ⚡
https://docs.nativescript.org/plugins/plugin-workspace-guide
Apache License 2.0
45 stars 11 forks source link

How to use an Angular component + template #5

Closed hrueger closed 3 years ago

hrueger commented 4 years ago

I'm trying to create an Angular-only plugin. I want to add an Angular component and a template. So I put the component file and the template file in packages/nativescript-squirrel-chat-ui/angular and added it to the declarations of the module in index.ts. But now I have two problems: When building the plugin, it says `

ERROR: Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("bble-content">
                        <GridLayout rows="auto, auto">
                            [ERROR ->]<Label class="sendername" row="0" *ngIf="!isContinuing(item) && !item.fromMe" [text]="item.sender.nam")
The pipe 'date' could not be found ("

                        <FlexboxLayout class="meta">
                            <Label [text]="[ERROR ->]item.date | date:'shortTime'" class="time"></Label>
                            <Label [text]="getSt")

So I removed the date pipe and changed *ngIf to [visibility]="[...] ? 'visible' : 'hidden'". Now the plugin builds successfully.

However, when I try to use the component in the demo-angular app, it is just blank.

My plugin is here: https://github.com/SchoolSquirrel/nativescript-plugins/tree/main/packages/nativescript-squirrel-chat-ui

Do you have any idea?

NathanWalker commented 4 years ago

@hrueger make sure the plugin's module includes NativeScriptCommonModule as that's where ngIf comes from etc.: https://github.com/SchoolSquirrel/nativescript-plugins/blob/main/packages/nativescript-squirrel-chat-ui/angular/index.ts#L8

You can always debug step through code in chrome dev tools to see how your plugin is behaving in the demo app.

hrueger commented 4 years ago

@NathanWalker Oh thanks, I missed the NativeScriptCommonModule. Sorry for that. Now it builds without any errors, however, the demo app still shows blank space where the UI is supposed to be.

Chrome Dev Tools show this: grafik

The tests label shows, but below it there is just nothing...

hrueger commented 4 years ago

@NathanWalker Sorry for another ping, but it's been almost two weeks ;-)

NathanWalker commented 3 years ago

@hrueger sorry for late reply here - from looks of your repo seems you got past this?

hrueger commented 3 years ago

@NathanWalker No, unfortulately, not. The demo-angular app still only displays the tests label (see comment above)

cvietor commented 3 years ago

@hrueger 2 minor issues there with your code:

import { CUSTOM_ELEMENTS_SCHEMA, NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { NativescriptSquirrelChatUiComponent } from './nativescript-squirrel-chat-ui.component';
import { NativeScriptCommonModule } from "@nativescript/angular";

@NgModule({
    declarations: [
        NativescriptSquirrelChatUiComponent,
    ],
    imports: [
        NativeScriptCommonModule,
    ],
    schemas: [
        NO_ERRORS_SCHEMA,
        CUSTOM_ELEMENTS_SCHEMA,
    ],
    exports: [
      NativescriptSquirrelChatUiComponent
    ]
})
export class NativeScriptSquirrelChatUiModule {}

Import your NativeScriptSquirrelChatUiModule in the demo-angular's squirrel-chat-ui.module.ts

import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
import { SquirrelChatUiComponent } from './squirrel-chat-ui.component';
import { NativeScriptSquirrelChatUiModule } from '@schoolsquirrel/nativescript-squirrel-chat-ui/angular';

@NgModule({
    imports: [
            NativeScriptCommonModule, 
            NativeScriptSquirrelChatUiModule, 
            NativeScriptRouterModule.forChild([{ path: '', component: SquirrelChatUiComponent }])],
    declarations: [SquirrelChatUiComponent],
    schemas: [NO_ERRORS_SCHEMA],
})
export class SquirrelChatUiModule {}

Then you should be good to go... Still an issue with that RadListView but i think that one is just missing an import

hrueger commented 3 years ago

@cvietor Thanks a lot!