加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs2

发布时间:2020-12-17 10:32:28 所属栏目:安全 来源:网络整理
导读:import {Component} from 'angular2/core';import {HighlightDirective} from './highlight.directive';import {Redify} from './directives';@Component({ selector: "app",directives:[Redify,HighlightDirective],template: ` p redify hello,liaojianguo


import {Component} from 'angular2/core';
import {HighlightDirective} from './highlight.directive';
import {Redify} from './directives';
@Component({
    selector: "app",directives:[Redify,HighlightDirective],template: `
        <p redify >hello,liaojianguo</p>
        <div>
          <input type="radio"  (click)="color='lightgreen'">Green
          <input type="radio"  (click)="color='yellow'">Yellow
          <input type="radio"  (click)="color='cyan'">Cyan
        </div>
      <p [myHighlight]="color">Highlight me!</p>
    `
})
export class App {
    constructor() {

    }
}


                

import {Directive,ElementRef,Renderer} from 'angular2/core';

@Directive({
  selector: '[redify]'
})
export class Redify {
  constructor(private _element: ElementRef,private renderer: Renderer) {
      renderer.setElementStyle(_element.nativeElement,'color','lightgreen');
  }
}

import {Directive,Input} from 'angular2/core';

@Directive({
    selector: '[myHighlight]',host: {
        '(mouseenter)': 'onMouseEnter()','(mouseleave)': 'onMouseLeave()'
    }
})

export class HighlightDirective {

    @Input('myHighlight') highlightColor:string;

    constructor(private el:ElementRef) {
    }

    onMouseEnter() {
        this._highlight(this.highlightColor);
    }

    onMouseLeave() {
        this._highlight(null);
    }

    private _highlight(color:string) {
        this.el.nativeElement.style.backgroundColor = color;
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读