组件未在路由器navigating.it初始化时仅在浏览器刷新时初始化?

时间:2017-11-07 04:37:49

标签: angular

当我给路由器导航数据没有在路由器页面更新时。但是当我刷新浏览器时,更新的数据可以显示在路由器页面。我想只重新加载组件。我尝试路由器导航首先导航到虚拟组件,然后导航到路由器页面。还有其他更好的方法???

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

    import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

    import { Appsettings } from '../../../app.settings'

    import { Http, Response, Headers } from '@angular/http';

    import { Router, Routes, RouterModule } from '@angular/router';

    import { ActivatedRoute } from '@angular/router';

    import { BaThemeSpinner } from '../../../theme/services';

    import { ToastrService,ToastrConfig } from 'toastr-ng2';

    @Component({

      selector: 'add-service-modal',

      styleUrls: [('./cat-modal.component.scss')],

      templateUrl: './cat-modal.component.html'

    })

    export class CatModal implements OnInit {

        modalHeader: string;

        modalContent: string;

        constructor(private activeModal: NgbActiveModal,private http:Http,

    private toastrService: ToastrService, private toastrConfig: ToastrConfig,

     private router: Router, private spinner: BaThemeSpinner)

     {

            toastrConfig.timeOut = 0;

        }

        approveCategory(userId,catId)

    {

            console.log(userId);

            console.log(catId);

            this.closeModal();

            this.spinner.showBlur();

            let params  =   {

                user_id     :   userId,

                cat_id      :   catId

            }

            let result=
          this.http.post(Appsettings.API__URL+'/adminUser/approveCategory',params 

    ).map((res: Response) => res.json());

            console.log(result);

            let subresult   =   result.subscribe((data) =>{

                this.spinner.hide();

                console.log('sub result');console.log(data);console.log('sub 

    result');

                if(data.status==1)

    {

                    this.toastrService.success('Category approved!',

     'Success!');

                    this.router.navigateByUrl('/DummyComponent', 

    {skipLocationChange: true}).then(()=>

                    this.router.navigate(["/pages/manageApproval"]));


                }

                else

                {
                    this.toastrService.success(data.message, 'Failed!');
                }

                });


                }

                denyCategory(userId,catId)

               {
            console.log(userId);

            console.log(catId);

            let params  =   {

                user_id     :   userId,

                cat_id      :   catId

            }

            this.closeModal();

            this.spinner.showBlur();

            let result=

     this.http.post(Appsettings.API__URL+'/adminUser/denyCategory', params 

    ).map((res: Response) => res.json());

            console.log(result);

            let subresult   =   result.subscribe((data) =>{

             {

             skipLocationChange: true}).then(()=>

                this.router.navigate(["/pages/manageApproval"]));

                this.spinner.hide();

            });

        }

        ngOnInit() {}

        closeModal() {

        this.activeModal.close();

        }
       }

1 个答案:

答案 0 :(得分:0)

我不确定您发布的代码是否完整,但我从您提出的问题中收集的内容是route params。根据您获取数据的方式,可能有查询字符串或其他内容,您可以将其用作路由参数。然后,当您刷新页面时,路由参数可以在激活的订阅中使用。找到激活的路线文档here

此外,here是执行路线参数的链接。希望有所帮助。