码迷,mamicode.com
首页 > 其他好文 > 详细

templating(模板)

时间:2016-01-23 07:48:18      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

templating特点:

Dynamic Loading动态加载

Directives指令

 

Component Directive组件指令示例:

@ComponentDirective({
    selector:‘tab-container‘,
    directives:[NgRepeat]
})
export class TabContainer {
    constructor(panes:Query<pane>) {
        this.panes = panes;
    }

    select(selectedpane:pane) { ... }
}

 

Decorator Directive装饰器指令示例:

@DecoratorDirective({
    selector: ‘[ng-show]‘,
    bind:{‘ngShow:‘: ‘ngShow‘},
    observe: {‘ngShow‘: ‘ngShowChanged‘}
})
export class NgShow {
    constructor(element:Element) {
        this.element = element;
    }

    ngShowChanged(newValue){
        if(newValue){
            this.element.style.display = ‘block‘;
        }else{
            this.element.style.display = ‘none‘;
        }
    }
}

 

Template Directive模板指令示例:

@TemplateDirective({
    selector: ‘nf-if‘,
    bind: {‘ngIf‘: ‘nfIfChanged‘}
})
export class NgIf {
    constructor(viewFactory:BoundviewFactory, viewport:ViewPort) {
        this.viewFactory = viewFactory;
        this.viewPort = viewPort;
        this.view = null;
    }

    ngIfChanged(value) {
        if (!value && this.view) {
            this.view.remove();
            this.view = null;
        }
        if (value) {
            this.view = this.viewFactory.createView();
            this.view.appendto(this.viewPort);
        }
    }
}

 

templating(模板)

标签:

原文地址:http://www.cnblogs.com/cjxhd/p/5152716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!