4番の角度でネストされた* ngforに問題があります。削除する必要があるのはparent ngforです。nullに設定して削除しようとしましたが、どちらも動作しません。ちょっとしたオプションがあります。基本的には親のngFor角の不正行為(少なくとも私が思う)を削除してエラーをスローするとどうなりますか?角度4ネスト* ngFor on削除親エラー
子供たちを取り除くことが可能なネストされた正しい方法を教えてもらえますか、今はアンゴラ4ではいくつかの異なる方法で行われていますか?
私は、このテストコンポーネント
@Component({
selector: 'test-parent',
templateUrl: './test.component.html',
})
export class TestComponent {
constructor() {
console.log("loaded menu");
setTimeout(()=> {
this.data.categories[1] = null;
}, 1000);
};
data = {
categories: [
{
name: 'name 1',
items: [
{
name: 'item 1'
},
{
name: 'item 2'
},
]
},
{
name: 'name 2',
items: [
{
name: 'item 3'
}
]
}
]
}
}
<div *ngFor="let c of data.categories">
{{c.name}}
<div *ngFor="let i of c.items">
{{i.name}}
</div>
</div>
は、これは私がより削除しようとした場合、それがnullのアイテムを読み取るしようとした以外、そこから多くを読み取ることができない、エラーで作成されました定義されていないnullの代わりに同じエラーが発生しました。 何らかの形でデータが変更されたことを通知する必要がありますか?もし私がthis.data.categoriesを試してみたら、それはサーバーに渡したいからユーザーが削除を押してしまったのでデータを削除したいのですが、それはうまく更新されます: '(信じられませんそのようなことは単純に不可能です?Array
から項目を除去するため
ERROR TypeError: Cannot read property 'items' of null
at Object.View_TestComponent_1.currVal_0 [as updateDirectives] (TestComponent.html:3)
at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:12613)
at checkAndUpdateView (core.es5.js:12025)
at callViewAction (core.es5.js:12340)
at execEmbeddedViewsAction (core.es5.js:12312)
at checkAndUpdateView (core.es5.js:12026)
at callViewAction (core.es5.js:12340)
at execComponentViewsAction (core.es5.js:12286)
at checkAndUpdateView (core.es5.js:12031)
at callViewAction (core.es5.js:12340)
at execEmbeddedViewsAction (core.es5.js:12312)
at checkAndUpdateView (core.es5.js:12026)
at callViewAction (core.es5.js:12340)
at execComponentViewsAction (core.es5.js:12286)
at checkAndUpdateView (core.es5.js:12031)
なぜアレイをスプライスしないのですか?うまくいかない理由はありますか? –
私はそれがこのテストシナリオで動作しようとしましたが、tbh私はループのトラフの異なるコンポーネントのためにネストされたように思ったそれは私がこの同じエラーを取得する必要がありましたalt30 –