0

I have typical easy situation but in that case @Input() does not working...

Child Component:

@Component({
  selector: 'app-test-grid',
  templateUrl: './test-grid.component.html',
  styleUrls: ['./test-grid.component.scss'],
})
export class TestGridComponent implements OnInit {
  @Input() memos: any[];

  constructor() {
    console.log(this.memos); // prints undefined
  }

  ngOnInit() {
    console.log(this.memos); // also prints undefined
  }
}
<div *ngIf="checker()">
  THIS IS DISPLAYED
  <app-test-grid>
    [memos]="test"
  </app-test-grid>
</div>

// parent component.ts
  test: number[] = [1, 2, 3, 4, 5, 6, 7];

  ngOnInit() {
    console.log(this.test); // print [1,2,3,4,5,6,7]
  }

 checker() {
    console.log('checker', this.test.length !== 0); // this prints true

    return this.test.length !== 0;
  }

what's wrong with this code? this is very rudimentary case... I tried to found some another posts related but I didn't found answer.

1 Answer 1

2

You closed the app-test-grid tag so the memos assignment is lost as the content of the component. Use this:

<app-test-grid [memos]="test">
</app-test-grid>
Sign up to request clarification or add additional context in comments.

3 Comments

Isn't this invalid html?
Sorry, forgot to close the tag. Now it's fine.
Looks that I'm idiot, my oversight, thank You !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.