在Angular 6中,你可以通过点击事件将字符串值传递给变量。以下是一个示例解决方法:
import { Component } from '@angular/core';
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
styleUrls: ['./example.component.css']
})
export class ExampleComponent {
inputValue: string;
passValue() {
console.log(this.inputValue);
// 在这里可以对传递的值进行其他操作
}
}
这样,当你在输入框中输入值后,点击按钮,输入框的值就会传递给变量,并在控制台中打印出来。你可以根据需要在passValue()
函数中对传递的值进行进一步的操作。