【发布时间】:2016-08-03 10:03:50
【问题描述】:
有没有办法从一个视图中调用组件函数?有点像。
我正在寻找一种方法来从我的ViewPage 调用组件上的show() 函数。
组件
//component.html
<template>
<div id="sidebar"></div>
</template>
// component.css
#sidebar {
display: none;
}
// component.ts
import {bindable} from 'aurelia-framework';
export class Sidebar {
@bindable data: Array<string>;
show = () : void => {
// Shows this specific side bar
}
hide = () : void => {
// Hides this specific side bar
}
}
查看
// view.html
<template>
<require from="./sidebar"></require>
<sidebar data.bind="data"></sidebar>
<button click.delegate="showSidebar()"></button>
<template>
// view.ts
export class ViewPage {
data: Array<string> = ["Hello", "I", "Am", "Sidebar", "Content"];
showSidebar = () : void => {
// how to show the side bar component here??
// I need something like sidebar.show();?
}
}
【问题讨论】:
标签: typescript components aurelia