Angular2 Decorator
2015-07-20 23:17
519 查看
1 at first, we use the (keyup) event handler to update the modify
but, if i wanna do something more when I use the keyup in all the input keyup?
we use the Decorator to decorator the event
2 import the Decorator
3 define the Decorator
4 use the decorator
5 the whole page code
@Component({ selector: 'my-app' }) @Template({ inline: '<h1>{{myName}}</h1>' + '<input type="text" #newname (keyup)/>' + '<h3 [style.color]="newname.value">{{newname.value}}</h3> ' })
but, if i wanna do something more when I use the keyup in all the input keyup?
we use the Decorator to decorator the event
2 import the Decorator
import {Component, Template, bootstrap, Decorator} from 'angular2/angular2';
3 define the Decorator
@Decorator({ selector: 'input', events: {'keyup': 'onKeyUp()'} }) class InputDecorator { onKeyUp() { console.log('do nothing'); } }
4 use the decorator
@Template({ inline: '<h1>{{myName}}</h1>' + '<input type="text" #newname />' + '<input type="text" #test/>' + '<h3 [style.color]="newname.value">{{newname.value}}</h3> ', directives: [InputDecorator] })
5 the whole page code
import {Component, Template, bootstrap, Decorator} from 'angular2/angular2';
@Decorator({ selector: 'input', events: {'keyup': 'onKeyUp()'} }) class InputDecorator { onKeyUp() { console.log('do nothing'); } }
@Component({
selector: 'my-app'
})
@Template({
inline: '<h1>{{myName}}</h1>' +
'<input type="text" #newname />' +
'<input type="text" #newnam />' +
'<h3 [style.color]="newname.value">{{newname.value}}</h3> ',
directives: [InputDecorator]
})
class MyApp {
constructor() {
this.myName = 'Jackey';
this.myFriends = [
{name: 'Jackey1', age: 25},
{name: 'Jackey2', age: 26}
];
}
}
bootstrap(MyApp);
相关文章推荐
- Angular2 How to Repeat a List
- Angular2 inject a Component into a Component
- Angular2 Template Syntax
- 1 Angular2 Set up
- 简话Angular 03 Angular内置表达式大全
- angular directive详解
- 创建 AngularJS 自定义过滤器,带自定义参数
- AngularJs记录学习04
- AngularJs记录学习03
- AngularJs记录学习02
- 【AngularJS】Yeoman安装
- 【AngularJS】【03】使用AngularJS进行开发
- angularjs 分页精华代码
- AngularJS学习笔记<1>环境配置
- 现在就开始使用AngularJS的三个重要原因
- 简话Angular 02 Angular控制器-作用域嵌套
- angularjs开发常见问题-2(angularjs内置过滤器)
- AngularJs解决方案笔记(1)
- AngularJS 表单验证
- AngularJS(一)