Having trouble with a nested Angular 2 component not showing up on the page?

I'm currently developing a mobile app with Angular 2 and Nativescript. In my setup, I have the HomeComponent, which includes a DockComponent. The DockComponent is functioning correctly, but now I want to break down the four buttons in the dock into separate components. To achieve this, I created a LoginComponent and attempted to include it in the DockComponent. However, it's not showing up as expected. Can you help me figure out what I did wrong?

I believed that by referencing the component's selector, importing the component, and adding it to the providers array of the parent component, it would work properly. What am I missing here?

Dock.Component.ts:

import {Component, OnInit} from "@angular/core";
import {Login} from "../Login/login.component";

@Component({
    selector: "dock",
    templateUrl: `Components/Dock/dock.html`,
    styleUrls: ["Components/Dock/dock.css"],
    providers: [Login]
})

export class Dock implements OnInit {

}

Login.Component.ts:

import {Component, OnInit} from "@angular/core";

@Component({
    selector: "login",
    templateUrl: `Components/Dock/Login/login.html`,
    styleUrls: ["Components/Dock/Login/login.css"],
    providers: []
})

export class Login implements OnInit {

    page: Page;
    ngOnInit() {
        this.page = <Page>topmost().currentPage;
    }
}

Dock.html:

<FAB row="8" col="0" icon="res://help" class="fab-button help" rippleColor="#f1f1f1" (tap)="fabTap()"></FAB>
<FAB row="8" col="1" class="fab-button bluetooth" icon="res://bluetoothg" rippleColor="#f1f1f1" (tap)="fabTap()"></FAB>
<login></login>
<FAB row="8" col="3" icon="res://plus" class="fab-button" id="add" rippleColor="#f1f1f1" (tap)="bluetoothAdd()"></FAB>
<ActivityIndicator row="8" col="3" busy="{{ isScanning }}" id="ActivityIndicator"></ActivityIndicator>

login.html:

(this content is copied and pasted from where <login></login> currently is in the dock.html file - where it was previously working fine)

<FAB row="8" col="2" icon="res://facebook" class="fab-button" id="facebook" rippleColor="#f1f1f1" (tap)="login('Facebook')"></FAB>
<FAB row="8" col="2" icon="res://google" class="fab-button" id="google" rippleColor="#f1f1f1" (tap)="login('Google')"></FAB>
<FAB row="8" col="2" icon="res://amazon" class="fab-button" id="amazon" rippleColor="#f1f1f1" (tap)="login('amazon')"></FAB>
<FAB row="8" col="2" icon="res://key" class="fab-button login" rippleColor="#f1f1f1" (tap)="socialClick()"></FAB>

Answer №1

Consider making the following change:

providers: [Login]

Replace it with:

directives: [Login]

The use of providers seems to be incorrect in this context. To grant a template access to a sub-component, you should declare it as a directive instead. Keep in mind that this declaration is an array, allowing for multiple components to be included. For additional information, check out the documentation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

.fetchevery(...).then has no function

I recently upgraded Angular to version 1.6.4. As a result, I made changes to the code by replacing .success and .error with .then However, now I am encountering the following error: An unexpected TypeError occurred: .getAll(...).then is not a function ...

Why does isDisplayed method in Protractor return "No element found using locator" instead of a boolean value?

In my code, I've created a function called isElementDisplayed which features a call to element.isDisplayed. I'm curious as to why the isDisplayed method sometimes returns No element found instead of a boolean value. isElementDisplayed(element: ...

Creating custom validation in AngularJS using CSS styling Incorpor

I need help figuring out how to display an error message when the field input is invalid. I can see that the correct classes are being applied to the element, like ng-dirty ng-invalid ng-invalid-pattern, so now I just need to make sure the error message sh ...

It seems that the maximum call stack size has been exceeded, resulting in a

Within this dropdown, I have incorporated a checkbox containing values in the form of an object. (refer to attached image) Every time I make a selection from the dropdown, there is a watch function that updates this new value, which is essentially an arra ...

Notification in AngularJS when navigating away from page

Despite finding similar posts, none of the solutions seem to work for me as intended. I'm attempting to set up an event handler to monitor a location change within a specific scope. The code snippet in question is: <!DOCTYPE html> <html lan ...

Currently in the process of configuring an ionic project, encountering a series of errors upon executing the npm install command

gyp ERR! configure error gyp ERR! stack Error: Unable to locate Python executable "python", please set the PYTHON environment variable. gyp ERR! stack at PythonFinder.failNoPython (C:\Program Files\nodejs\node_modules\npm\node_ ...

What is the best way to activate a select list once data retrieval from the server has been successfully completed using an asynchronous call, despite the initial ng-disabled setting being 'true'?

Currently, I have multiple select lists in my HTML form where user inputs are gathered. My objective is as follows: 1) Initially, I want to disable the 'select' list using ng-disabled='true' since the controller does not have the data ...

Utilize ngDoc to document a constant in your codebase

What is the process for documenting a constant with ngDoc? I am unable to find any specific documentation related to angular for documenting values registered with .constant, and it appears that using jsDoc syntax for constants does not result in generatin ...

Tips on using class-validator @isArray to handle cases where only a single item is received from a query parameter

Currently, I am attempting to validate a request using class-validator to check if it is an array. The inputs are sourced from query parameters like this: /api/items?someTypes=this This is what my request dto resembles: (...) @IsArray() @IsEn ...

Using mergeMap in conjunction with retryWhen allows for the resumption of retries from the exact point of failure, without needing

I have a list of URLs, the number of which is unknown until it stops (depending on some condition). This is how I am currently using them: from(observableUrls) .pipe( mergeMap(url => callHttpService(url) , 4), retryWhen( // Looking f ...

Embedding the Angular Material date picker when the page loads using an HTML tag

Currently, I am in need of a solution where the material datepicker (the datepicker itself, not just the icon) is visible on the page by default. The goal is to always have the datepicker displayed without needing to click on an icon. If anyone could pro ...

Techniques for transferring data from ng-click to ng-model

In the development of a foreign language dictionary app, I have implemented a filter that utilizes a regular expression to transform each word in the search results into a clickable URL. This enables users to easily navigate through the app and conduct new ...

Location of the bundled Webpack index.html file while running locally on a Nativescript WebView

I am currently working on a hybrid app project that involves both NativeScript and Angular. To integrate the two, I have set up a WebView and consolidated all my Angular project files into a folder within my NativeScript project. As part of this setup, I ...

What is the importance of having a reference path for compiling an AngularJS 2 project using gulp-typescript?

I wanted to modify the Angular Tour Of Heros project to utilize gulp from this Github Repository. This is the gulpfile.json file I came up with: const gulp = require('gulp'); const del = require('del'); const typescript = require(&apo ...

ReactiveForm recursion encounters difficulty locating formGroups within the template

In order to dynamically create a large form with around 400 inputs, I am utilizing a meta-data object to pass input-specific information such as type of input, select options, step size, etc. However, I have encountered an issue where the parent form is no ...

Nuxt3 - TS2339: The 'replaceAll' property is not found on the 'string | string[]' type in Nuxt3

Hey there! I've been experimenting with the replaceAll() method within my Nuxt3 project and encountered a strange error. Folder Structure ───pages │ └───Work │ │ index.vue │ │ [Work].vue Template <templat ...

Display a modal dialog using HttpInterceptor

@Injectable() export class MyInterceptor implements HttpInterceptor { intercept(req : HttpRequest<any>, next : HttpHandler) : Observable<HttpEvent<any>> { //display a modal dialog to wait for user response before proceeding with t ...

Specifying the type of "this" within the function body

After going through the typescript documentation, I came across an example that explains how to use type with this in a callback function. I am hoping someone can assist me in comprehending how this callback will operate. interface DB { filterUsers(fil ...

Accessing data retrieved from an API Subscribe method in Angular from an external source

Below is the Angular code block I have written: demandCurveInfo = []; ngOnInit() { this.zone.runOutsideAngular(() => { Promise.all([ import('@amcharts/amcharts4/core'), import('@amcharts/amcharts4/charts') ...

Issue encountered with ASP.Net Core on AWS Serverless: The middleware for the SPA default page was unable to locate and return the default page '/index.html'

Everything works flawlessly with my ASP.Net Core 6.0 application with Angular on Visual Studio, but once deployed to AWS Serverless and accessing '/', an error occurs. The default SPA page middleware cannot serve the default page '/index.h ...