Question about how to findViewById within a component, within a component


#1

Hi. I’m only a week into this, so please don’t give me a hard time.

I’ve been tinkering around with a slide drawer where the drawer content is specified in a separate component. The drawer contains a ListView which I’d like to grab a reference to in the component, this is so that I can set the tableFooterView to remove the empty rows from showing (and also to learn) I’ve tried a few things:

undefined

@ViewChild(ListView) public listView: ListView;

undefined

console.log(topmost().getViewById("listView"));

this one crashes because (Can’t resolve all parameters for SlidedrawerComponent)

constructor(protected page: Page) { }
console.log(this.page.getViewById("listView"));

the component that is embedded into the RadSlideDrawer’s tkDrawerContent

<GridView >
    <ListView id="listView"  [items]="items"  >
        <ng-template let-item="item">
            ***
        </ng-template>
    </ListView>
</GridView>

The problem is that I can’t seem to inject a page variable via the constructor because it’s not instantiated like a normal page.

Should I be specificing a provider somewhere?
Or should I be grabbing the page somewhere in the component module’s onLoad function?

Any help would be much appreciated.
Thanks, David.


#2

You must include NativeScriptCommonModule in your module which adds the provider for Page.

@ViewChild may be recommended over assigning actual ids when using Angular.


#3

Thanks, I’ll give this a try soon. Is there any documentation about this? Specifically why you have to include NativeScriptCommonModule in your module as I can’t find anything about this.


#4