Closed sebawita closed 7 years ago
Additionally, I've tested the same code in a brand new {N} project (outside of the Seed project) and the ListView behaves, as expected. So there must be something in the seed project that makes it behave like this.
I had the same problem in my app, where the ng-template
was being ignored. That is what you are seeing.
I solved it by adding the following nativescript modules to my component's module:
import { NativeScriptModule } from 'nativescript-angular/nativescript.module';
import { NativeScriptFormsModule } from 'nativescript-angular/forms';
Actually to a tns
version of my component's module.
So, give it a try. Create a home.module.tns.ts
, that add those 2 modules to it's import list. Something like:
import { NgModule, Optional, SkipSelf, NO_ERRORS_SCHEMA } from '@angular/core';
// app
import { HomeComponent } from './components/home/home.component';
import { SHARED_MODULES } from './home.common';
// tns
import { NativeScriptModule } from 'nativescript-angular/nativescript.module';
import { NativeScriptFormsModule } from 'nativescript-angular/forms';
@NgModule({
imports: [
NativeScriptModule,
NativeScriptFormsModule,
...SHARED_MODULES
],
declarations: [HomeComponent],
schemas: [
NO_ERRORS_SCHEMA
]
})
export class HomeModule {
constructor( @Optional() @SkipSelf() parentModule: HomeModule) {
if (parentModule) {
throw new Error('HomeModule already loaded; Import in root module only.');
}
}
}
See if that fixes it.
@fourctv thank you for the help. It was enough to add NativeScriptModule
.
For some reason I thought that the modules from app.module.tns.ts
would be available globally (like a set of defaults), but it looks like imports go away as soon as you load another NgModule.
When I try use a ListView with the data coming from an array, the ListView creates a label for each item and binds to it. When I provide my own
ng-template
nothing changes and the contents of the array are still displayed as before.This happens with both iOS and Android.
To reproduce:
Open
src/app/home/components/home/home.component.ts
add the following code:items: string[] = ['a', 'b', 'c'];
Open
src/app/home/components/home/home.component.tns.html
and replace it withResult
The expected behaviour:
a ListView with 3 labels with the text:
Actual behaviour:
a ListView with 3 labels with the text: