0

I'm new to the AngularJS and having a problem loading up data with element ID. I've checked I can print out any text value to the modal already but again, text data with element ID isn't working. Any idea?

list.component.html

<a mat-flat-button color="accent" (click)="openDialog()" href="/details/{{element._id}}" target="_blank" class="fctButton">View Details</a>

list-component.ts

    import * as moment from "moment";
    import { Observable } from "rxjs";
    import { APIService } from "../../services/api.service";
    import { CSVService } from "../../services/csv.service";
    import { FormControl } from "@angular/forms";
    import { map, startWith } from "rxjs/operators";
    import { Component, OnInit } from "@angular/core";
    import { Router, ActivatedRoute } from "@angular/router";
    import { TooltipPosition } from "@angular/material/tooltip";
    import { MatSnackBar } from "@angular/material/snack-bar";
    import { MatDatepickerInputEvent } from "@angular/material/datepicker";
    import { MatDialog } from "@angular/material/dialog"; // Dialog
    import { DetailElementComponent } from "../details/detail/detail-element/detail-element.component";
    
    @Component({
      selector: "app-list",
      templateUrl: "./list.component.html",
      styleUrls: ["./list.component.sass"],  template: "{{element}}",
})
export class ListComponent implements OnInit {

  constructor(
    private api: APIService,
    private csvService: CSVService,
    private router: Router,
    private route: ActivatedRoute,
    private _snackBar: MatSnackBar,
    // public dialog: MatDialog,
    public dialog: MatDialog,
    @Inject(MatDialog) public data: { }
  ) {}
    
      openDialog() { // Dialog
        this.dialog.open(DetailElementComponent);
      }

detail-element.compoenent.html

    <div *ngIf="isLink(element); then link else notLink"> </div>
    <ng-template #link>
        <a target="_blank" href="{{element}}"> {{ element }} </a>
    </ng-template>
    <ng-template #notLink>
        {{ element }} **// This line won't print on the Modal popup**
        Hello **// Now this line will be print without any problem**
    </ng-template>

detail-element.component.ts

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


    
    @Component({
      selector: 'app-detail-element',
      templateUrl: './detail-element.component.html',
      styleUrls: ['./detail-element.component.sass']
    })
    export class DetailElementComponent implements OnInit {
    
      constructor() {}
    
      @Input() element: any;     // data to display
    
      ngOnInit(): void {
      }
    
      isLink(item): boolean {
        return typeof item === 'string' && item.includes('http') && !item.includes(' ');
      }
    }
JOPimentel
  • 139
  • 1
  • 11
Ian Lee
  • 43
  • 1
  • 7
  • Can you show the `detail-element.component.ts` ? How is `element` filled ? You don't inject anything when you open the modal... – Random Feb 21 '21 at 18:31
  • `import { Component, OnInit, Input } from '@angular/core'; import { MatDialog } from '@angular/material/dialog';` `@Component({ selector: 'app-detail-element', templateUrl: './detail-element.component.html', styleUrls: ['./detail-element.component.sass'] }) export class DetailElementComponent implements OnInit { constructor() {} @Input() element: any; // data to display ngOnInit(): void { } isLink(item): boolean { return typeof item === 'string' && item.includes('http') && !item.includes(' '); } }` – Ian Lee Feb 21 '21 at 18:41
  • Sorry It a weird format. – Ian Lee Feb 21 '21 at 18:43
  • does the `#link`-template work? – katzenhut Feb 21 '21 at 18:54
  • Sorry katzenhut. I'm still learning and not 100% what #link-template is. – Ian Lee Feb 21 '21 at 18:57
  • instead of putting code in comments, you may edit your question to add details we're asking ;) – Random Feb 21 '21 at 19:00
  • A modal cannot have `@Input()` attributes. Please see [how to inject data in a ng-mat modal](https://material.angular.io/components/dialog/overview#sharing-data-with-the-dialog-component) – Random Feb 21 '21 at 19:02
  • Yes! thanks Random. I edited the question. And Thank you! I am reading the link that you've sent me. – Ian Lee Feb 21 '21 at 19:10
  • This is how far I got Random. – Ian Lee Feb 21 '21 at 19:29

0 Answers0