Angular之模版引用变量
A template reference variable is often a reference to a DOM element within a template. It can also be a reference to an Angular component or directive or a web component.
模板引用变量通常用来引用模板中的某个 DOM 元素,也可以引用 Angular 组件、指令、Web Component(自定义元素标签)。
store.component.ts
import { Component, OnInit } from '@angular/core';@Component({selector: 'app-store',templateUrl: './store.component.html',styleUrls: ['./store.component.css']
})
export class StoreComponent implements OnInit {name = 'SUV';constructor() { }ngOnInit() {}}
store.component.html
<span #title>4S店span>
<button (click)="print(title.innerHTML);">单击button><input type="tel" #tel value="021-12345678"/>
<button (click)="print(tel.value);">单击button><app-car #car>app-car>
<button (click)="print(car.name);">单击button>
car.component.ts
import { Component, OnInit } from '@angular/core';@Component({selector: 'app-car',templateUrl: './car.component.html',styleUrls: ['./car.component.css']
})
export class CarComponent implements OnInit {name = 'SUV';constructor() { }ngOnInit() {}}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
