[Angular 2] 9. Replace ng-modle with #ref & events
Let's say you want to write a simple data bing app. when you type in a text box, somewhere in the application will show the result.
In Angular 1, you can use ng-model to finish all those stuff, but in angular 2, the concept behind has changed.
<!-- index.html -->
<html>
<head>
<title>Angular 2 Quickstart</title>
<script src="https://github.jspm.io/jmcriffey/bower-traceur-runtime@0.0.87/traceur-runtime.js"></script>
<script src="https://jspm.io/system@0.16.js"></script>
<script src="https://code.angularjs.org/2.0.0-alpha.26/angular2.dev.js"></script>
</head>
<body>
<!-- The app component created in app.ts -->
<hello></hello>
<script>System.import('app');</script>
</body>
</html>
import {
Component,
View,
bootstrap
} from 'angular2/angular2';
@Component({
selector: 'hello'
})
@View({
template: `
<div>
<label for="name">Name: </label>
<input type="text" #ref (keyup)/>
<hr />
<h2>{{ref.value}}</h2>
</div>
`
})
export class Hello{
}
bootstrap(Hello);
We add a #ref, which you can name it anything you want after '#'. And then use 'ref.value' to the actual value from it.
But only this won't work.. you also need to watch it. In Angualr 2, this is acomplished by add even listener to the dom. Here we use '(keyup)'.
[Angular 2] 9. Replace ng-modle with #ref & events的更多相关文章
- angular报错:angular.min.js:118Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq
报错代码如下: <div ng-controller="HelloAngular"> <p>{{greeting.text}},angular</p& ...
- Angular CLI 启动 版本ng 4
npm install -g angular-cli ng -v ng new project_name cd project_name ng serve 浏览器打开输入 localhost:4200
- [Angular Directive] Build a Directive that Tracks User Events in a Service in Angular 2
A @Directive is used to add behavior to elements and components in your application. This makes @Dir ...
- angular 2 - 001 ng cli的安装和使用
angular cli 创建项目和组件 ng new my-app --skip-install cd my-app cnpm install ng serve localhost:4200 angu ...
- Angular源代码学习笔记-原创
时间:2014年12月15日 14:15:10 /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http:// ...
- 将地图定位封装为ng指令
一.HTML结构<div tabindex="-1" class="modal fade in active modal-map" role=" ...
- Ngnice-国内ng学习网站
今天给angular新手介绍一个国内开源的ng学习网站http://www.ngnice.com/这是由一批ng爱好者在雪狼大叔的带领下共同开发完成,致力于帮助更多的ng新人,他们分别是: ckken ...
- 国内ng学习网站
Ngnice-国内ng学习网站2015-01-25 21:30 by 破狼, 534 阅读, 3 评论,收藏, 编辑 今天给angular新手介绍一个国内开源的ng学习网站http://www.ngn ...
- Angular 4 学习笔记 从入门到实战 打造在线竞拍网站 基础知识 快速入门 个人感悟
最近搞到手了一部Angular4的视频教程,这几天正好有时间变学了一下,可以用来做一些前后端分离的网站,也可以直接去打包web app. 环境&版本信息声明 运行ng -v @angular/ ...
随机推荐
- Linux进程和进程边界
1. 进程和线程 2. 手机操作系统的发展 3. 进程的地址空间边界 4. 进程边界的安全围栏: Crash的不可扩延性 5. 进程边界的安全围栏: 全局数据和服务的不可访问性 http://www. ...
- Python中使用中文
python的中文问题一直是困扰新手的头疼问题,这篇文章将给你详细地讲解一下这方面的知识.当然,几乎可以确定的是,在将来的版本中,python会彻底解决此问题,不用我们这么麻烦了. 先来看看pytho ...
- iOS: 学习笔记, 值与引用类型(译自: https://developer.apple.com/swift/blog/ Aug 15, 2014 Value and Reference Types)
值和引用类型 Value and Reference Types 在Swift中,有两种数据类型. 一是"值类型"(value type), 它是每一个实例都保存有各自的数据,通常 ...
- button 垂直分布
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];//button的类型 button.frame = CGRectMak ...
- IntraWeb.v14.0.32安装及破解指南
一.下载 首先从这里下载14.0.32版本的IntraWeb: 链接:http://pan.baidu.com/s/1c0rjnKO 密码:8kv2 二.卸载旧版 1. 我的Delphi版本是XE6, ...
- 如何分析matlab程序的主要效率问题
利用profile on 在需要分析效率的程序段前后加入 profile on profile off 然后,在common line中输入profile viewer即可观察到这段程序的效率
- Shoot the Bullet
zoj3229:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3442 题意:一个摄影师,在n天内给m个女神拍照.每个女神至少要 ...
- 【POJ1330】Nearest Common Ancestors(树链剖分求LCA)
Description A rooted tree is a well-known data structure in computer science and engineering. An exa ...
- View的getLeft, getRight, getTop, getBottom
View的getLeft, getRight, getTop, getBottom方法得到的分别是相对于其父组件原点坐标不同方向的距离 网上找了张图说明: 其中right和left的计算方法如下: r ...
- bzoj2734
非常巧妙地题目对于一个数x列出这样的矩阵x 2x 4x 8x ……3x 6x 12x 24x ………………………………不难方案数就是求取数不相邻的方案数考虑矩阵宽不超过logn,所以可以用状压dp解决 ...