嗨,伙计们,我需要一点帮助,因为我似乎不能让它工作。我想我可能是用了错误的语法什么的。
我目前正在使用YO https://github.com/jvandemo/generator-angular2-library构建角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构建包,然后将其导入到另一个应用程序中,然后导入模块。
然后,我按以下方式使用该组件:
<sample-component hello="koos"></sample-component>它工作得很好,并显示了正确的消息。
我的问题是,当我像这样绑定hello属性时
<sample-component [hello]="koos"></sample-component>我在后端有变量koos = 'hello I am koos;',它根本不绑定到它?
我应该用其他方法来做这件事吗?还有其他方法来绑定“输入”和“输出”变量吗?
你的洞察力将不胜感激。
根据请求,父组件:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.less']
})
export class AppComponent implements OnInit {
koos: 'Ek is Koos';
}显然,我删除了其他代码,因为这是唯一需要的部分。
发布于 2018-03-07 09:03:15
这是你的错误:
koos: 'Ek is Koos'; // < --- you create type 'Ek is Koos'解决方案是这样创建:
koos:string = 'Ek is Koos';https://stackoverflow.com/questions/49147368
复制相似问题