-1

以下の追加機能を呼び出すボタンをクリックすると、データはデータベースに追加されますが、フロントエンド自体には追加されません。ページをロードせずにどのように追加しますか?私はルータを使用している場合角2:ページを読み込まないで追加する方法

addSection(section: Section) { 
 
    section.name = section.name.trim(); 
 
    if(section.name != ''){ 
 
     this.onToggleDialogBox(); 
 
     this.sectionService 
 
      .registerSection(section) 
 
      .subscribe(
 
       res => alert(res.message), 
 
       error => console.log(error) 
 
     ) 
 
    }else{ 
 
     alert('Enter name.'); 
 
    } 
 
}

、ここで必要なコードは次のとおりです。

constructor(
 
     private router: Router, 
 
     private route: ActivatedRoute, 
 
     private sectionService: SectionService 
 
    ) {} 
 

 
this.router.navigate(['/information/sections']);

+0

'subscribe'関数の' res'では、あなたが望む変更を手作業で行う必要があります。 – SaiUnique

+0

リンクが見つかりません@RahulSingh – Char

+0

はい。それは "ページが見つかりません"と言います@RahulSingh – Char

答えて

1

は、サーバと別のセクションを追加するには2つの方法で、1を持っていますフロントエンドにセクションを追加する。セクションが正常にサーバーに追加されたら、フロントエンドにもセクションを追加します。

addSectionToFront(section){ /* TODO: add to front-end */} 

addSection(section){ 
    ... 
    this.sectionService.register(section).subscribe(
    // server call succeeded. Now add section locally 
    () => this.addSectionToFront(section), 
    error => {} 
); 
} 
関連する問題