zoukankan      html  css  js  c++  java
  • Angular2 Decorator

    1 at first, we use the (keyup) event handler to update the modify

    @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);
    

      

  • 相关阅读:
    [整理]ADB命令行学习笔记
    3、HTML的body内标签1
    2、HTML的head内标签
    1、HTML的本质以及在web中的作用
    3.11-3.15 HDFS HA
    3.9-3.10 分布式协作服务框架Zookeeper
    3.6-3.8 分布式环境启动、测试
    3.1-3.5 分布式部署hadoop2.x的准备和配置
    2.28 MapReduce在实际应用中常见的优化
    2.27 MapReduce Shuffle过程如何在Job中进行设置
  • 原文地址:https://www.cnblogs.com/lihaozhou/p/4663067.html
Copyright © 2011-2022 走看看