Embedded template does not utilize property binding ngif with any directive

I am currently working on an Angular (Angular2 RC4) application and I'm facing some challenges running it with the live server in nodejs.

Any suggestions on how to troubleshoot the error showing up in the Chrome console would be greatly appreciated.

Error in Chrome console:

browser_adapter.ts:82
EXCEPTION: Template parse errors:
Property binding ngif not utilized by any directive on an embedded template. Please ensure that the property name is spelled correctly and all directives are listed in the "directives" section. ("
</video-list>

[ERROR ->]<video-detail *ngif="selectedVideo" [video]="selectedVideo">
</video-detail>"): AppComponent@8:0**

app.component.ts

import {Input, Output, Component} from '@angular/core'
import {Config} from './config.service'
import {Video} from './video'
import {VideoListComponent} from './videolist.component'
import {VideoDetailComponent} from './videodetail.component'

@Component({
    selector: 'my-app',
    templateUrl: 'app/app.component.html',
    directives: [VideoListComponent, VideoDetailComponent]
})
export class AppComponent {
    title = Config.TITLE_PAGE;
    videos: Array<Video>;
    selectedVideo : Video;

constructor() {
    this.videos = [
        new Video(1, "Test", "www.test.com", "Test Description"),
        new Video(2, "Test 2", "www.test2.com")
    ]
}

onSelectVideo(video) {
    //console.log(JSON.stringify(video));
    this.selectedVideo = video;
}
}

app.component.html

<h1 class="jumbotron">
    {{title}}
</h1>
<!-- concept [binding]  videos receives values from AppComponent.ts-->
<video-list [videos]="videos" 
    (selectVideo)="onSelectVideo($event)">
</video-list>

<video-detail *ngif="selectedVideo" [video]="selectedVideo">
</video-detail>

package.json

{
"name": "angularbase",
  "version": "1.0.0",
  "description": "Base Project",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "project",
    "base",
    "angular",
    "angular2"
  ],
  "author": "Eduardo Cordeiro",
  "license": "ISC",
  "dependencies": {
    "@angular/common": "^2.0.0-rc.4",
    "@angular/compiler": "^2.0.0-rc.4",
    "@angular/core": "^2.0.0-rc.4",
    "@angular/forms": "^0.2.0",
    "@angular/http": "^2.0.0-rc.4",
    "@angular/platform-browser": "^2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "^2.0.0-rc.4",
    "@angular/upgrade": "^2.0.0-rc.4",
    "angular2-in-memory-web-api": "0.0.7",
    "bootstrap": "^3.3.6",
    "rxjs": "^5.0.0-beta.6",
    "systemjs": "^0.19.27",
    "zone.js": "^0.6.12"
  }
}

systemjs.config.js

(function (global) {

    // systemjs map config
    var map = {
        'app': 'app', // 'dist',
        'rxjs': 'node_modules/rxjs',
        'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
        '@angular': 'node_modules/@angular'
    };

    // packages that can be loaded by systemjs
    // if the file is not found in the map
    var packages = {
        'app': { main: 'boot.js', defaultExtension: 'js' },
        'rxjs': { defaultExtension: 'js' },
        'angular2-in-memory-web-api': { defaultExtension: 'js' },
    };

    var packageNames = [
        '@angular/common',
        '@angular/compiler',
        '@angular/core',
        '@angular/http',
        '@angular/platform-browser',
        '@angular/platform-browser-dynamic',
        '@angular/router',
        '@angular/router-deprecated',
        '@angular/testing',
        '@angular/upgrade',
    ];

    // map angular packages according to the packageName provided above
    packageNames.forEach(function (pkgName) {
        packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
    });

    var config = {
        map: map,
        packages: packages
    }

    if (global.filterSystemConfig) { global.filterSystemConfig(config); }
    System.config(config);

})(this);

tsconfig.json

{
"compilerOptions": {
    "target": "es6",
    "module": "system",
    "sourceMap": true,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "watch": true 
},
"exclude": [
    "node_modules"
]
}

Answer №1

It's important to remember that Angular2 directives are case-sensitive. For example, the directive *ngIf must have a capital 'I' in order for it to work properly.

If you try to use *ngif instead, Angular will throw an error because it doesn't recognize this as a valid directive.

Answer №2

In order to utilize *ngIf, it is necessary to import the CommonModule into either the root module (AppModule) or the specific module where you intend to use it (for example, TestModule).

import { CommonModule } from "@angular/common";
...
@NgModule({
    imports: [CommonModule]
    ...
})
export class AppModule { }

Answer №3

Note: primarily relevant to individuals utilizing VSCode as their code editor.

Following the creation of an Angular 13 application, this message popped up in my VS Code workspace. The remedy was to ensure that the Angular Language Service extension is updated, preventing the setting "use the legacy view engine language service" from being enabled.

For additional information, visit this link.

Answer №4

Great news! I managed to resolve the issue by looking into node_modules/@angular/common/index.d.ts and locating that specific line.

2181 static ɵdir: i0.ɵɵDirectiveDeclaration<NgIf<any>, "[ngIf]", never, { "ngIf": { "alias": "ngIf"; "required": false; }; "ngIfThen": { "alias": "ngIfThen"; "required": false; }; "ngIfElse": { "alias": "ngIfElse"; "required": false; }; }, {}, never, never, true, never>;

Next step is to replace the previous line with the following:

static ɵdir: i0.ɵɵDirectiveDeclaration<NgIf<any>, "[ngIf]", never, { "ngIf": "ngIf"; "ngIfThen": "ngIfThen"; "ngIfElse": "ngIfElse"; }, {}, never, never, true, never>;

I'm happy to be of help :)

Answer №5

If encountering this issue with a personalized structural directive, verify that the directive includes an @Input using matching name as the directive. Additionally, ensure to import the directive if it functions independently.

@Directive({
  selector: '[personalDirective]',
  standalone: true,
})
export class PersonalDirective {
  @Input('personalDirective') personalDirective;

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

Update the data in Firebase, but revert it back to the original state after a few seconds with the use of "angularFire."

I'm currently working on updating data in the Firebase Realtime Database using Angular and AngularFire. The issue I'm facing is that even though the data changes successfully, it reverts back to the original data after a few seconds. Below is the ...

What is the reason behind the input text field not preserving its value when disabled?

Currently, I am working on a basic input field that utilizes Angular within StorybookJS. However, I have encountered an issue where the input text field does not maintain its value when the disabled attribute is set to true. For example, if I manually typ ...

Unable to make custom font work in TailwindCSS and ReactJS project

I have incorporated a custom font into my projects using React, TypeScript, TailWind, and NextJS. The font file is stored in the /fonts directory with the name Glimer-Regular.ttf. To implement the font, I added the following code snippet to my global.css ...

Is Axios the sole option for API calls when utilizing Next.js with SSG and SSR?

Can someone clarify the best practice for data fetching in Next.js? Should we avoid using axios or other methods in our functional components, and instead rely on SSG/SSR functions? I'm new to Next.js and seeking guidance. ...

What steps are involved in developing an Angular library wrapper for a pre-existing Javascript library?

Imagine having a vanilla Javascript library that is commonly used on websites without any frameworks. How can you create an Angular library that can be easily installed via npm to seamlessly integrate the library into an Angular application? The process o ...

What is the method for creating an object type that necessitates a key determined by a variable?

Is it feasible to create a custom type in TypeScript that can check if a given key exists within the Type definition? I am specifically using noUncheckedIndexAccess: true configuration. interface one { foo: string; bar: string; } interface two { b ...

Encountering an issue while trying to utilize Vuex in Vue with TypeScript

I recently utilized npm to install both vue (2.4.2) and vuex (2.3.1). However, when attempting to compile the following code snippet, I encountered the following error: https://i.stack.imgur.com/0ZKgE.png Store.ts import Vue from 'vue'; import ...

Navigating the intricacies of debugging sub-domains in Angular projects using Visual Studio Code (VS

Currently working on a massive project utilizing micro-services. The unique design for clients/tenants requires visiting their specific subdomain to select a particular tenant. For example, https://ClientA.localhost:4200 and https://ClientB.localhost:4200. ...

Every day, I challenge myself to build my skills in react by completing various tasks. Currently, I am facing a particular task that has me stumped. Is there anyone out there who could offer

Objective:- Input: Ask user to enter a number On change: Calculate the square of the number entered by the user Display each calculation as a list in the Document Object Model (DOM) in real-time If Backspace is pressed: Delete the last calculated resul ...

Secure mustache templates for data validation

Is there a method to achieve the following?: my-custom-template.mstach Hello {{name}}! script.js import { readFileSync, writeFileSync } from 'fs'; import * as Mustache from 'mustache'; export interface Person { name: string; } ...

Angular2: The comeback of accessing a getter after the service constructor has completed (using HTTP Get)

I have a requirement for my app where I need to utilize List.json to create a list, which forms the core of my application. To ensure this list is shared across all components, I have opted to establish a service. Within this service, I call my JSON file ...

typescript challenging syntax within mix-ins

type Constructor<T> = new (...args: any[]) => T; function f1<T extends {}>(naked: Constructor<T>): any { return class dressed extends naked { } // error } function f2<T extends Constructor<{}>>(naked: T): any { re ...

What is the reason that TypeScript cannot replace a method of the base class with a subtype?

Here's a straightforward example. type Callback<T> = (sender: T) => void; class Warehouse<T> { private callbacks: Callback<T>[]; public constructor(callbacks: Callback<T>[]) { this.callbacks = callbacks; ...

Failed service worker registration: Angular 9 PWA malfunctioning following Universal Prerendering integration

Issue encountered in the console log An error was thrown due to an unsupported MIME type ('text/html'). Service worker registration failed with: DOMException: Failed to register a ServiceWorker for scope ('https://localhost:4000/') wi ...

"Error TS2339: The property specified does not exist within type definition", located on the input field

When a user clicks a specific button, I need an input field to be focused with its text value selected entirely to allow users to replace the entire value while typing. This is the markup for the input field: <input type="text" id="descriptionField" c ...

Creating an Array in TypeScript

Is it possible to declare a global array in Typescript so that it can be accessed using "this" from any part of the code? In javascript, I would typically declare it as "var anArray=[]". What is the equivalent way of doing this in Typescript? Using anArra ...

Tips for accessing the FormControlName of the field that has been modified in Angular reactive forms

My reactive form consists of more than 10 form controls and I currently have a subscription set up on the valueChanges observable to detect any changes. While this solution works well, the output always includes the entire form value object, which includ ...

Retrieve category descriptions in Angular using their corresponding IDs

During the edit form process, I am sending categories by ID but displaying them as descriptions in options. Here is an example: new-campaign.html <mat-label>categories</mat-label> <mat-select multiple formControlName="VehicleCa ...

What is the reason for the regeneration of the 2D array?

I have a method called generateWeights() that retrieves random values in an array; And a method named learn() that calls the changeWeights() method to alter the values in the array. Expected: Prior to invoking the learn() method, I anticipate receiving an ...

The router's handler function sends back a collection of objects, but for some reason, the client is not receiving them in JSON format even though the response

I am currently developing an Express.js project using Typescript. In my project, I have defined an enum and an interface as follows: export enum ProductCategory { ELECTRONICS = 'electronics', CLOTHING = 'clothing', TOYS = & ...