我正在尝试构建一个简单的组件,只是一个打印参数但未显示参数的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() {
}
}
结果:
我无法弄清楚我错过了什么。
答案 0 :(得分:2)
您的代码与文档(https://angular.io/docs/ts/latest/api/core/Input-var.html)相同,但[test]="Something"
除外,您尝试编写test="Something"
了吗?
我认为[]
语法只能采用组件的变量。
答案 1 :(得分:1)
我不确定,但请尝试[测试] =&#34;&#39;某事&#39;&#34;