Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 未定义特定@Input参数的值_Angular_Ionic2 - Fatal编程技术网

Angular 未定义特定@Input参数的值

Angular 未定义特定@Input参数的值,angular,ionic2,Angular,Ionic2,在我基于AngularJs 2的Ionic 2项目中,我有一个下面的组件 import { Component, Input } from '@angular/core'; @Component({ selector: 'items-list', templateUrl: 'items-list.html' }) export class ItemsListComponent { @Input() type; @Input() count; items: Array&l

在我基于AngularJs 2的Ionic 2项目中,我有一个下面的组件

import { Component, Input } from '@angular/core';

@Component({
  selector: 'items-list',
  templateUrl: 'items-list.html'
})

export class ItemsListComponent {
  @Input() type;
  @Input() count;

  items: Array<{ url: string, title: string }>;

  constructor() {
  }

  ngOnInit() {
    console.log(this.type); //undefined
    console.log(this.count); //10

    this.items = [];

    for (let i = 1; i < this.count; i++) {
      this.items.push({
        url: 'assets/' + this.type + '/' + i + '.png', title: 'Style # ' + i
      });
    }

    console.log(JSON.stringify(this.items));

  }
}
从'@angular/core'导入{Component,Input};
@组成部分({
选择器:“项目列表”,
templateUrl:'items list.html'
})
导出类ItemsListComponent{
@Input()类型;
@输入()计数;
项目:阵列;
构造函数(){
}
恩戈尼尼特(){
console.log(this.type);//未定义
console.log(this.count);//10
此参数为.items=[];
for(设i=1;i
我正在我的一个页面中使用该组件,如下所示,它显示了模板内容

<items-list [type]="children" [count]=10></items-list>

但“类型”输入值始终未定义。我能够在控制台中看到“计数”输入的“10”值


为什么“this.type”总是未定义,为什么“this.count”显示实际值?

我创建的组件也有同样的问题。如果您的类型是字符串,请不要使用
[type]=“children”
,使用
type=“children”

在父组件上的
类型值是什么?在父组件上传递的值是问题中提到的“children”。什么是
children
?你如何分配价值?您是否检查了父组件中的
未定义的
?希望我已经解释了我所拥有的以及如何在控制台中检查值。您添加了子组件的代码,您收到的
未定义的
表示父组件有问题。哇。你救了我,大人:)谢谢你给这个学习者的简单提示。