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

[Angular 2] Exposing component properties to the template

时间:2015-11-01 06:54:05      阅读:409      评论:0      收藏:0      [点我收藏+]

标签:

Showing you how you can expose properties on your Controller to access them using #refs inside of your template.

 

// letterSelect.ts

import {Component, View, FORM_DIRECTIVES, NgFor} from ‘angular2/angular2‘;

@Component({
    selector: ‘letter-select‘
})
@View({
    directives: [NgFor,FORM_DIRECTIVES],
    template: `
        <select [(ng-model)]="selectedLetter">
            <option *ng-for="#letter of letters">{{letter}}</option>
        </select>
    `
})

export class LetterSelect {
    letters: string[] = [‘e‘, ‘s‘, ‘w‘];
    selectedLetter: string = ‘e‘;
    constructor() {

    }
}

 

todoList.ts

import {Component, View, NgFor, FORM_DIRECTIVES} from ‘angular2/angular2‘;
import {TodoService} from ‘./todoService‘;
import {TodoItemRender} from ‘./todoItemRender‘;
import {StartsWith} from ‘./startsWith‘;
import {LetterSelect} from ‘./letterSelect‘;

@Component({
    selector: ‘todo-list‘
})
@View({
    pipes: [StartsWith],
    directives: [NgFor, TodoItemRender, FORM_DIRECTIVES, LetterSelect],
    template: `
          <div>
                <todo-item-render
                    *ng-for="#todo of todoService.todos | startsWith:‘title‘:letterSelect.selectedLetter"
                    [todoinput]="todo"
                >
                </todo-item-render>
                <letter-select #letter-select></letter-select>
          </div>
    `
})

export class TodoList{
    constructor(
        public todoService:TodoService
    ){

    }
}

 

[Angular 2] Exposing component properties to the template

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/4926643.html

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