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

inject a Component into a Component

时间:2015-07-20 23:22:34      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

1 add clock.es6 file

import {Component, Template, bootstrap} from ‘angular2/angular2‘;
@Component({
    selector:‘clock‘
})

@Template({
    inline:‘<h1>{{name}}</h1>‘
})

export class Clock{
    constructor(){
        this.name = ‘Clock‘
    }
}

  ps:remember to export the class and add to the system path

    System.paths = {
        ‘angular2/*‘: ‘angular2/*.js‘,
        ‘rtts-assert/*‘: ‘rtts-assert/*.js‘,
        ‘app‘: ‘app‘,
        ‘clock‘:‘clock‘
    };

    System.import(‘app‘);

 2 add the component to your component

import {Component, Template, bootstrap, For} from ‘angular2/angular2‘;
import {Clock} from ‘./clock‘;


@Component({
    selector: ‘my-app‘
})

@Template({
    inline:‘<h1>{{myName}}</h1>‘ +
    ‘<input type="text" #newname (keyup)/>‘ +
    ‘<h3 [style.color]="newname.value">{{newname.value}}</h3>‘ +
    ‘<button (click)="onClick(newname.value)">change value</button>‘ +
    ‘<clock></clock>‘,
    directives:[Clock]
})


class MyApp {

    constructor() {
        this.myName = ‘Jackey‘;
    }

    onClick(newName){
        console.log(newName);
    }
}


bootstrap(MyApp);

  remember : 1 import the profile 2 directives:[Clock] 3 add to the html <clock></clock> 

inject a Component into a Component

标签:

原文地址:http://www.cnblogs.com/lihaozhou/p/4662950.html

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