我遇到了一个场景,需要对ngOnchanges上的数据进行一些处理(因为数据是通过来自父组件的@Input数据绑定属性传递的)。在此转换过程中,我需要使用在ngOnInit中初始化的属性。我试图直接使用它,但它的值是未定义的。谁能让我知道我怎样才能做到这一点。下面是我的场景的示例代码。
ParentComp HTML
<myParent [data]="list$ | async"></myParent>
ChildComp TS
export class {
@Input() data : any ; //data from parent
b
我希望你做得很好。
我试图通过访问API中的数据来实现一个FormsBuilder。通过@ The ()将数据向下推到其子组件。
然而,数据被按下,提供并成功地显示,但是当ngOnChangess第一次尝试接收数据时,我仍然得到了这个错误。
ERROR TypeError: Cannot read property 'choice_set' of null
at StyleTypeQuestionComponent.setFormValues (style-type-question.component.ts:34)
at StyleTypeQuestionCo
我有一个组件
@Component({
selector: 'my-component',
template: '<div id="myDiv">Some value comes here dynamically from server</div>',
})
class MyComponent implements OnInit {
@Input()
ngOnInit() {
//execute my function when a content change is occured in #my
我有两个组件,app.component和encours.component,我在app.Component的导航栏中有一个选择,它需要在每次更改时向encours.component发送值。我第一次就能得到价值,但之后,我什么也得不到。我有一个名为dataService的服务,用于通信,我使用路由器出口进行路由,所以我无法从路由器出口标签中传递数据,我试图在encours.component中实现ngOnChange方法,但它不起作用。
这是我的服务代码:
@Injectable()
export class DataService{
private serviceSource = n
我试图@输入一个对象列表;这会导致@Input变量未定义。
工作内容: home.component.html:
<p>
<it-easy [mycount]="countItem" (result)="PrintResult($event)"></it-easy>
home works for {{countItem}}!
</p>
<p>
calculation result is: {{calcResult}}
</p>
以及home.component.ts中的代