Encountering a Problem with Angular 2 Directive *ng-for

Recently started experimenting with the beta version of Angular 2.0 and encountered an error stating "angular is not defined" while trying to add directive: [angular.ngFor].

If you want to take a look, here is the Plunker URL: http://plnkr.co/edit/ULHddLRqPFXvNG7NPo93?p=preview

Thank you in advance for any assistance.

Answer №1

Incorporating the directive is no longer necessary as it is now a core feature. Remember to use ngFor instead of ng-for.

Sample template:

<h2>{{teamName}}</h2>

<ul>
  {{players}}
  <li *ngFor="#player of players"> {{player}}</li>
</ul>

Your component:

(function(app) {
  app.AppComponent =
    ng.core.Component({
      selector: 'my-app',
      templateUrl: 'app/home.html',
    })
    .Class({
      constructor: function() {
        this.teamName = 'ManchesterUnited';
        this.players = ['Ronney','Mata','Depay','Jhones','Smalling','Schiderlin'];
      }
    });
})(window.app || (window.app = {}));

Trust this information serves you well, Thierry

Answer №2

When working with alpha.52 templates, it's important to note that they are case-sensitive. In these cases, it's recommended to utilize the ngFor directive instead. The same principle also applies to other directives such as ngIf and ngModel.

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

Managing a single Angular project with multiple apps that share common features: A guide

Imagine having multiple Angular 'apps' with similar features and functions, where one product needs to be customized for different clients with slightly varying needs. The challenge lies in developing within a single code base. Using feature mod ...

In Angular Mat Stepper, only allow navigation to active and completed steps

For a project, I created a sample using React.js and Material UI. Here is the link to the project: https://stackblitz.com/edit/dynamic-stepper-react-l2m3mi?file=DynamicStepper.js Now, I am attempting to recreate the same sample using Angular and Material, ...

Alert message will be displayed upon clicking on stepper titles in Angular 10

I need to implement an alert when the user clicks on the second stepper labeled 'Fill out your address'. In addition to displaying a red border around the empty form field, I also want to show an alert message. I have already set up a function ca ...

When utilizing Angular 2, this message is triggered when a function is invoked from the Observable

One of my services is set up like this: @Injectable() export class DataService { constructor(protected url: string) { } private handleError(error: Response) { console.log(this.url); return Observable.throw(new AppError(error)); ...

I'm having trouble getting my Ionic Angular App to start up properly. When I try to launch it, it just gets stuck on the splash screen and displays an error message saying "ReferenceError

The challenge I am facing involves developing an IOS app using ionic v7 and angular v15.2. While the app functions smoothly in the browser, upon deployment to my iPhone (iphone 13 pro, running IOS 15.6), I encounter a perplexing error message within XCode: ...

How can you add a Git submodule without specifying a URL?

I am looking to integrate my Angular folder as a submodule into my primary directory. The Angular folder has already been initialized as a git repository. It is currently a local folder on my Windows machine with no URL. After successfully initializing gi ...

What could be causing Angular to replace the original variable?

As a newcomer to Angular, I've been working on this code for hours now. Hopefully, it will all come together for someone out there who can make sense of it. export class QuizComponent implements OnInit { originalArray: IArray[] = []; tempArray: I ...

Creating Dynamic Routes and Implementing Component Restrictions in Angular 2

Currently in the midst of designing an Angular 2 application, I find myself faced with some fundamental questions that could significantly impact the overall design. I'm struggling to determine the "right angular way" to address these concerns. Here a ...

Resolve the upstream dependency conflict that occurs during the installation of ng-bootstrap/ng-bootstrap

Encountering an error while attempting to install npm install --save @ng-bootstrap/ng-bootstrap. Seeking assistance in resolving this issue. npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a ...

Troubleshooting CORS problem: Angular 2 and AspNetCore WebApi encounter error with preflight response having invalid HTTP status code 401

Hello there! I am currently working on implementing a straightforward token based authentication method in an Angular 2 RC6 application against an AspNetCore WebApi project that I developed using Visual Studio 2015. If you're interested, I have uploa ...

Using Rxjs for MongoDB Document References: A Step-by-Step Guide

Currently, I am working on an app using Ionic2/rc0. In my singleton service, I have a ReplaySubject that maintains the consistency of the current user throughout the entire application. Everything is functioning properly, and I can easily subscribe to it a ...

Encountering errors with ng build --prod in Angular 2, but no issues when running ng serve

After attempting to deploy my Angular 2 app to Heroku, I encountered a daunting list of errors when trying to build for production. Interestingly, the app runs smoothly without any issues or errors when using 'ng serve'. You can view the full li ...

Developing an Angular application and deploying it onto the server

I've been working on an angular6 application and I need to create a build to test it on my server. Currently, when I use ng server, the application runs without any errors in my browser. c:\Users\emiry\Desktop\Angular\Proje ...

Display the HTML tag inside a cell of a mat-table

I am currently exploring options to display an HTML tag within a cell of a mat-table in Angular. My goal is to show a colored circle next to the cell value. I have searched online for solutions, but haven't found one that works. If anyone has any insi ...

Can the detectChanges() method in Angular cause any issues when used with the form control's valueChanges event?

Within my parent Component, I am working with a formGroup and updating its value using patchValue method. ngAfterViewInit() { this.sampleform.controls['a'].patchValue ...} I then pass this form to a child component in the parent component's ...

Using Angular 2 to convert and display data as a particular object type in

I have recently developed a basic application using the Angular2 tutorial as my guide. Initially, I established a straightforward "Book" model: /** * Definition of book model */ export class Book { public data; /** * Constructor for Book ...

Preventing users from entering past dates in Angular 6 - A step-by-step guide

Here is my current code snippet: ngOnInit() { let now = new Date(); this.date = formatDate(now, "dd/mm/yyyy",'en-US'); console.log("dateFormat :",this.date); } This is the html part of my code: <input type="date" [min]={{da ...

Tips for adding items to a Form Array in Angular

I am working on a project with dynamic checkboxes that retrieve data from an API. Below is the HTML file: <form [formGroup]="form" (ngSubmit)="submit()"> <label formArrayName="summons" *ngFor="let order of form.controls.summons.controls; let i ...

The scrollTo() function does not function properly on iOS devices

When I try to scroll to my category list, the command works on Android but not on iOS. Here is a code example: @ViewChild(Content) content: Content; scrollTo() { this.content.scrollTo(0, 100, 200); } - <button ion-button (click)="scrollTo()"> ...

"Unlock the power of NGXS by leveraging the raw state values

I'm having trouble locating an example in the NGXS documentation that demonstrates how to properly type the state object. Specifically, I am looking for guidance on typing the return value of the snapshot method of Store. For instance: this.store.sn ...