Angular 2: How to add without loading page


After clicking a button that calls the add function below, the data is being added into the database but not on the frontend itself. How do you add it without loading the page?

addSection(section: Section) { =;
    if( != ''){
                res => alert(res.message),
                error => console.log(error)
        alert('Enter name.');

If I use Router, here are the necessary codes:

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



Try the subscription of rxjs. After executing the method in service, append .finally. In your component, subscribe to that method with the subscription. So that if that method is executed, it will reflect on the component without loading the page

Answered By – user8653311

Answer Checked By – Clifford M. (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.