我正在尝试将 ngModel 数据从一个组件传递到另一个组件,第二个组件可以使用该数据在其 html 中执行函数。
我正在使用@Input(),但我不知道如何通过超链接发送该数据。
home.component.ts
import { Component, OnInit, Input } from '@angular/core';
import { BasePageComponent } from 'src/app/partials/base-page/base-page.component';
import { ActivatedRoute } from '@angular/router';
import { SurveyService } from 'src/app/services/survey.service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent extends BasePageComponent implements OnInit {
@Input() surveyName: string;
surveys: any[];
constructor(
route: ActivatedRoute,
private surveyService: SurveyService) {
super(route);
}
ngOnInit() {
this.surveys = this.surveyService.getAll();
}
}
home.component.html
<div
class="col-4 col-sm-4 col-md-4 col-lg-4"
*ngFor="let survey of surveys"
>
<a class="btn btn-outline-secondary" href="/about" role="button">Begin Survey</a>
</div>
about.component.html
<input type="text" [(ngModel)]="surveyName" oninput="loadSurvey(surveyName)">
现在,这没有任何作用。我的预期结果是,当我单击Begin Survey时,将使用方法about.component.html
加载我单击的调查loadSurvey(surveyName)