Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ionic ngfor in component



I'm going crazy, i've created a new component and he's working fine. Now i would like to use this on two pages.

Then i've created a component module (/components/all-components.module.ts) like this :

import { NgModule } from '@angular/core';
import { TagsComponent } from './tags/tags.component';
import { IonicModule } from '@ionic/angular';


@NgModule({
  imports: [IonicModule],
  declarations: [
    TagsComponent
  ],
  exports: [
    TagsComponent
  ]
})

export class AllComponentsModule {}

I've added on app.module.ts the AllComponentsModule and on my 2 pages module i have added same.

Now, my component work fine when i'm displaying text or variable, my console.log return the data, but if i use *ngFor nothing appear.

Finally, here's my component

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

@Component({
  selector: 'app-tags',
  templateUrl: './tags.component.html',
  styleUrls: ['./tags.component.scss'],
})
export class TagsComponent implements OnInit {

  @Input() userTags: any;

  constructor() {
  }

  ngOnInit() {
      console.log(this.userTags);
  }
}

And the view:

<p>hi</p>
<div *ngFor="let tag of userTags">
  <p>{{tag?.name}}</p>
</div>

Ok i don't understand why but if i use a module to store all of components. On my all-components.module.ts i have to put the CommonModule to interpret *ngFor, *ngIf, etc.

With CommonModule import all working fine !

Here's the code updated:

import { NgModule } from '@angular/core';
import { TagsComponent } from './tags/tags.component';
import { CommonModule } from "@angular/common";

@NgModule({
  imports: [CommonModule],
  declarations: [
    TagsComponent
  ],
  exports: [
    TagsComponent
  ]
})

export class AllComponentsModule {}
Comment

ngfor ionic example

<ion-select placeholder="Select" [(ngModel)]="selected">
    <ion-option *ngFor="let item of strings" [value]="item">{{item}}</ion-option>
</ion-select>`
Comment

PREVIOUS NEXT
Code Example
Javascript :: js clone element 
Javascript :: disable submit button if input is empty 
Javascript :: $(this).text() in jquery return white space 
Javascript :: how to stop browser back js 
Javascript :: nl2br javascript 
Javascript :: type of javascript 
Javascript :: how to append the dropdown values by jquery each function 
Javascript :: sotre json on chrome storage 
Javascript :: loop through object in array javascript 
Javascript :: js onchange input value event listene 
Javascript :: [Error - 10:52:45 PM] Failed to load jshint library 
Javascript :: javascript string contains string 
Javascript :: javascript sort array of objects by key value 
Javascript :: discord js check if person banned 
Javascript :: error vuejs from chokidar enospc 
Javascript :: new line in p tag react 
Javascript :: capitalise first letter js 
Javascript :: javaScript getMilliseconds() Method 
Javascript :: onclick inline function react 
Javascript :: js new date short format 
Javascript :: prevent paste in input 
Javascript :: how to integrate redux dev tool to react application 
Javascript :: convert svg to base64 javascript 
Javascript :: javascript generate random numbers 
Javascript :: react js nesting 
Javascript :: xmlhttprequest javascript 
Javascript :: how to declare a variable inside a class in javascript 
Javascript :: dictionary in javascript 
Javascript :: convert date to readable format javascript 
Javascript :: Reached heap limit Allocation failed - JavaScript heap out of memory nodejs 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =