【问题标题】:Parameter in Ionic2 custom component not displayedIonic2 自定义组件中的参数未显示
【发布时间】:2016-05-22 14:41:40
【问题描述】:

我正在尝试构建一个简单的组件,只是一个打印参数但未显示参数的 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() {
  }
}

结果:

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

【问题讨论】:

标签: components ionic2


【解决方案1】:

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

我认为[] 语法只能接受组件的变量。

【讨论】:

  • 就这么简单...非常感谢
【解决方案2】:

我不确定,但请尝试 [test]="'Something'"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-20
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多