Ionic2自定义组件中的参数未显示

时间:2016-02-11 17:14:43

标签: components ionic2

我正在尝试构建一个简单的组件,只是一个打印参数但未显示参数的div:

的test.html

<ion-content padding class="getting-started">
   <my-component [test]="Something"></my-component>
</ion-content>

test.ts

import {Page} from 'ionic-framework/ionic';
import {MyComponent} from './myComponent';

@Page({
    templateUrl: 'build/pages/test/test.html',
    directives: [MyComponent]
})

export class TestPage {
    constructor() {
    }
}

myComponent.ts

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

@Component({
  selector: 'my-component',
  template: `
    <div>Param: {{test}}</div>
   `,
})

export class MyComponent {
  @Input() test;
  constructor() {
  }
}

结果:

No text displayed

我无法弄清楚我错过了什么。

2 个答案:

答案 0 :(得分:2)

您的代码与文档(https://angular.io/docs/ts/latest/api/core/Input-var.html)相同,但[test]="Something"除外,您尝试编写test="Something"了吗?

我认为[]语法只能采用组件的变量。

答案 1 :(得分:1)

我不确定,但请尝试[测试] =&#34;&#39;某事&#39;&#34;