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
<!-- 引用DOM元素 --> <span #title>4S店</span>
<button (click)="print(title.innerHTML);">单击</button> <input type="tel" #tel value="021-12345678"/>
<button (click)="print(tel.value);">单击</button> <!-- 引用Angular组件 --> <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() {
}
}
Angular之模版引用变量的更多相关文章
- Java基础-被final修饰的引用变量的指向
final修饰的引用变量一旦初始化赋值之后就不能再指向其他的对象,那么该引用变量指向的对象的内容可变吗?看下面这个例子: public class Test { public static void ...
- PHP GC垃圾回收机制之引用变量回收周期疑问
普通的引用变量的销毁大家都知道, 当unset的时候如果refcount = 0 则认为无用, 销毁. 但是手册中提到一点会有递归引用的问题,很是奇葩 代码如下 <?php $a = 1; $a ...
- C++引用变量(转)
引用变量 c++中引用变量的使用: 定义: int rate=80; int & pt=rate 1.pt 是引用变量,申明引用变量时必须将其初始化.pt 和rate 的值指向相同的内存变量 ...
- c#问答篇:对象与引用变量-----初学者的困惑
转自:http://www.cnblogs.com/huangyu/archive/2004/08/02/29622.html 从宏观的角度来看,对象是类的实例.比如: //定义一个名为Someone ...
- C++ primer(八)--内联函数 引用变量 引用传递函数参数 函数重载/模板/模板具体化
一.内联函数 常规函数和内联函数的区别在于C++编译器如何将他们组合到程序中.编译过程的最终产品是可执行程序--由一组机器语言指令组成.运行程序时,操作系统将这些指令载入到计算机内存中,因此每 ...
- C++引用变量学习
版权所有,转载请注明来源 (1)reference variable(rv) 主要用处是作为方程的形式参数,使用rv 可以直接对原数据进行操作而不是该数据的拷贝,节省了时间和空间,尤其是对于结构体以及 ...
- C++学习笔记29,引用变量(1)
引用变量在创建的时候就必须初始化.无法创建一个未被初始化的引用. #include <iostream> using namespace std; int main() { int x=1 ...
- [DB][mybatis]MyBatis mapper文件引用变量#{}与${}差异
MyBatis mapper文件引用变量#{}与${}差异 默认,使用#{}语法,MyBatis会产生PreparedStatement中.而且安全的设置PreparedStatement參数,这个过 ...
- PHP关于foreach使用引用变量的坑
写PHP好多年,但仍然会犯低级错误,今天遇到个 foreach中引用变量时的坑,PHP版本为 5.6.12 代码如下: <?php $arr = ['a', 'b', 'c', 'd', 'e' ...
随机推荐
- virtualBox下Centos系统扩展LVM磁盘空间
工具准备:下载Gparted Live CD,一个分区管理工具(根据安装的32,64位版本选择对应链接).https://sourceforge.net/projects/gparted/files/ ...
- APP-11-视觉技术-通用文字识别
1.Postman测试 2.参数 https://cloud.baidu.com/doc/OCR/OCR-API.html#.EC.DF.48.27.9B.69.A4.2C.54.1B.DC.95.6 ...
- SpringBoot配置发送邮件
一.导入jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...
- EMQ笔记
飞行窗口(Inflight Window)保存当前正在发送未确认的Qos1/2消息.窗口值越大,吞吐越高:窗口值越小,消息顺序越严格. 当客户端离线或者飞行窗口(Inflight Window)满时, ...
- python模块os
一.os模块概述 Python os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.(一语中的) 二.常用方法 1.os.name 输出字符串指示正在使用的平台 ...
- SQL 语句 写法
SELECT * FROM article where userid=4 order by sort asc LIMIT 0,10; 先根据写where 条件,再排序,在LIMIT.
- 如何使用JBDC修改数据
1.JDBC取得数据库Connection连接对象conn, Connection conn=null; //数据库连接对象 String strSql=null; //sql语句对象 // ...
- jQuery图片延迟加载插件:jquery.lazyload
----------------------------------------------------------------------------------------------- clas ...
- Intellij IDEA使用spring-boot-devtools无效解决办法(2018年3月9日11:46:00)
步骤一:pom.xml中加入: <dependency> <groupId>org.springframework.boot</groupId> <artif ...
- C# Excel To DataTable
原地址忘了 需引用NPOI,引用方法:项目引用那儿右键 => 管理NuGet程序包 => 游览 =>输入NPOI =>选中NPOI后安装(一般是第一个) /// <sum ...