0

I would use How to do inter communication between a master and detail component in Angular2? to solve this problem but it's not allowed now to use directive. How to pass my array from first component to another?

import { Component} from '@angular/core';
import { Router } from '@angular/router';

import { MdDialog, MdDialogRef } from '@angular/material';


@Component({
  selector: 'app-flashcards',
  templateUrl: './flashcards.component.html',
  styleUrls: ['./flashcards.component.scss'],

})
export class FlashcardsComponent {
  dialogRef: MdDialogRef<MnemoDialog>;

  constructor (private router: Router,public dialog: MdDialog) {} //router in function

  mnemo = ['assets/images/family.png', 'assets/images/blood-m.png','assets/images/obrazek.jpg','assets/images/asdfas.jpg'];
  n = 0;

  myMnemo = this.mnemo[this.n];

  nextImg() {

      this.myMnemo = this.mnemo[this.n];
      n++;

    }
  }

}


@Component({
  selector: 'mnemo-dialog',
  template: `<img fxFlex="70%"  md-card-image src="{{ myMnemo }}">`
})
export class MnemoDialog {

}
Community
  • 1
  • 1
Tomasz Cysewski
  • 569
  • 3
  • 10
  • 15

1 Answers1

0
@Component({
  selector: 'mnemo-dialog',
  template: `<img fxFlex="70%"  md-card-image src="{{ source }}">`
})
export class MnemoDialog {
    @Input()source: YOURDATATYPE;
}

And in your flashcards.component.html something like this:

 <mnemo-dialog [source]="myMnemo"></mnemo-dialog>

Or is this not allowed?

Batajus
  • 5,831
  • 3
  • 25
  • 38
  • nah, not working, I dont use mnemodialog like this , I call fuction inside flashcards for this component open() { this.dialogRef = this.dialog.open(MnemoDialog); } – Tomasz Cysewski Feb 12 '17 at 10:27