大家好,我需要一些帮助,因为我似乎无法让它工作。我想我可能使用了不正确的语法或其他东西。
我目前正在使用 YO https://github.com/jvandemo/generator-angular2-library构建 Angular 4 库
所以除了@Input
装饰器之外一切都在工作。
这里有一些简单的代码
import { Component, Input } from '@angular/core';
@Component({
selector: 'sample-component',
template: `<h1>Sample component {{hello}}</h1>`
})
export class SampleComponent {
@Input('hello') hello: string;
constructor() {
}
}
我使用 npm 构建包,然后导入 dist 到另一个应用程序,然后导入模块。
然后我按如下方式使用此组件:
<sample-component hello="koos"></sample-component>
它工作得很好,并显示了正确的消息。
我的问题是关于当我像这样绑定 hello 属性时
<sample-component [hello]="koos"></sample-component>
我koos = 'hello I am koos;'
在后端有变量,它根本没有绑定到它?
我应该使用其他方式来做到这一点吗?还有另一种绑定@Input 和@Output 变量的方法吗?
您的洞察力将不胜感激。
根据父组件的要求:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.less']
})
export class AppComponent implements OnInit {
koos: 'Ek is Koos';
}
我显然删除了其他代码,因为这是唯一需要的部分。