Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.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 角度构件教程主/详图构件。为什么要改变父母?_Angular_Ionic2_Angular Components - Fatal编程技术网

Angular 角度构件教程主/详图构件。为什么要改变父母?

Angular 角度构件教程主/详图构件。为什么要改变父母?,angular,ionic2,angular-components,Angular,Ionic2,Angular Components,我在跟踪调查。我的问题是为什么hero也会在父级中更改,如果它发送的变量不同,并且没有绑定hero。我认为这决不能发生 。相关代码: <h2>My Heroes</h2> <ul class="heroes"> <li *ngFor="let hero of heroes" [class.selected]="hero === selectedHero" (click)="onSelect(hero)"> <spa

我在跟踪调查。我的问题是为什么
hero
也会在父级中更改,如果它发送的变量不同,并且没有绑定
hero
。我认为这决不能发生

。相关代码:

<h2>My Heroes</h2>
<ul class="heroes">
  <li *ngFor="let hero of heroes"
    [class.selected]="hero === selectedHero"
    (click)="onSelect(hero)">
    <span class="badge">{{hero.id}}</span> {{hero.name}}
  </li>
</ul>

 <app-hero-detail [hero]="selectedHero"></app-hero-detail>
我的英雄
    {{hero.id}{{hero.name}

这是因为
hero
被作为引用传递。在下面的
hero细节组件中
ngModel
直接更改
hero.name

因为它们是直接更改的,所以不需要为父级发出事件

英雄:

<app-hero-detail [hero]="selectedHero"></app-hero-detail>
<input [(ngModel)]="hero.name" placeholder="name"/>

所以[hero]也是对heroes
arrray中)。请注意,如果不是这样的话,
[class.selected]=“hero===selectedHero”
将永远无法工作。您知道我在哪里可以深入研究引用?谢谢。我认为你的思路是对的。国际海事组织称,angular.io上的官方文件非常全面,也非常有说服力。