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' ...
随机推荐
- Props文件属性读取
Properties props=new Properties(); try { props.load(new InputStreamReader(getClass().getResourceAsSt ...
- html表单中get与post之间的区别
当用户在 HTML 表单 (HTML Form) 中输入信息并提交之后,有两种方法将信息从浏览器传送到 Web 服务器 (Web Server). 一种方法是通过 URL,另外一种是在 HTTP Re ...
- (已解决)搭建ssm框架时给springmvc传入对象传不进去,传单个字符串可以
问题如题: springmvc会自动解析传入的内容,只要将表单中的对象名字和pojo一一对应,否则会报错. jsp默认好像是会加上请求头. 如果要是用其他的方式去给接口传入对象.要加上请求头. Con ...
- 【372】Kaggle 相关经验
参考:机器学习系列(3)_逻辑回归应用之Kaggle泰坦尼克之灾 参考:Kaggle泰坦尼克特征工程和模型融合 『解决一个问题的方法和思路不止一种』『没有所谓的机器学习算法优劣,也没有绝对高性能的机器 ...
- 24 week 4 安装 docker
安装docker 出现问题 解决办法https://blog.csdn.net/VOlsenBerg/article/details/70140211 发现链接超时,然后就https://blog.c ...
- (转) VS2010 Addins 外接程序(插件)开发
http://www.cnblogs.com/Leo_wl/archive/2013/03/21/2973886.html VS2010 Addins 外接程序(插件)开发 阅读目录 VS2010 A ...
- MySQL C#连接ySQL保存当前时间,时分秒都是0,只有日期
原因:MySQL的字段格式是:date 解决: 1.把 字段格式 改为 datetime 2.映射 的字段类型 也要改为 datetime
- 吴裕雄 python神经网络(7)
import numpy as npnp.random.randint(0,49,3) # -*- coding:utf-8 -*-import kerasfrom keras.models impo ...
- tabel 选中行变色和取当前选中行值等问题
先把代码贴出来 $("#tableId tbody tr").mousedown(function () { $('#tableId tr').each(funct ...
- 'Could not find first log file name in binary log index file'的解决办法
数据库主从出错: Slave_IO_Running: No 一方面原因是因为网络通信的问题也有可能是日志读取错误的问题.以下是日志出错问题的解决方案: Last_IO_Error: Got fatal ...