Go to particular Route's div elementHow can I select an element in a component template?In Angular, how do you determine the active route?Reset service variable on route change in Angular2Angular 2 Protractor: Click div elementElement doesn't get destroyed on router navigation after manipulating DOMHow to pass different template variables to one button in angular2?element not visible but present - protractorangular route animation change dynamicallyOpen clicked li's child divAngular: Hiding/showing elements by ngIf or Toggling a class?

How does Loki do this?

Two monoidal structures and copowering

Roman Numeral Treatment of Suspensions

Is expanding the research of a group into machine learning as a PhD student risky?

Implement the Thanos sorting algorithm

Crossing the line between justified force and brutality

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

How does the UK government determine the size of a mandate?

Customer Requests (Sometimes) Drive Me Bonkers!

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

Trouble understanding the speech of overseas colleagues

Is this apparent Class Action settlement a spam message?

when is out of tune ok?

How do I find the solutions of the following equation?

How can a function with a hole (removable discontinuity) equal a function with no hole?

Unreliable Magic - Is it worth it?

How to run a prison with the smallest amount of guards?

Short story about space worker geeks who zone out by 'listening' to radiation from stars

How to Reset Passwords on Multiple Websites Easily?

How do I extract a value from a time formatted value in excel?

What is the difference between "behavior" and "behaviour"?

Is there a korbon needed for conversion?

Anatomically Correct Strange Women In Ponds Distributing Swords

System.debug(JSON.Serialize(o)) Not longer shows full string



Go to particular Route's div element


How can I select an element in a component template?In Angular, how do you determine the active route?Reset service variable on route change in Angular2Angular 2 Protractor: Click div elementElement doesn't get destroyed on router navigation after manipulating DOMHow to pass different template variables to one button in angular2?element not visible but present - protractorangular route animation change dynamicallyOpen clicked li's child divAngular: Hiding/showing elements by ngIf or Toggling a class?













0















I have two routes. From one route I need to get another route's div element by button click. I done a similar way with id(#) that we do in HTML but It's not working out. Can you suggest a best way to do in Angular>



Route One (/route1)



<div class="div1">
<p>hi</p>
</div>

<div class="div2">
<p>hello</p>
</div>


Route two (/route2)



<button (click)="getDiv()"></button>


TS



getDiv()

this.router.navigate(['/route1']); // I need to get div1 of route1 here










share|improve this question






















  • So you basically want to do an anchor link using routing? If yes, that's not how route works.

    – Jacopo Sciampi
    Mar 8 at 11:27











  • By this.router.navigate(['/route1']); , we can go to particular route know. So, Is there is any way to get the div of that route is what I am asking

    – Felix Christo
    Mar 8 at 11:30











  • You could send the id of the div as param and handle the scrolling on your target component

    – FabioG
    Mar 8 at 11:30











  • gotodiv(id) const element = document.getElemnetById(id); if (element) element.scrollIntoView( behavior: 'smooth', block: 'start' );

    – Joel Joseph
    Mar 8 at 11:35












  • This is typescript

    – Felix Christo
    Mar 8 at 11:36















0















I have two routes. From one route I need to get another route's div element by button click. I done a similar way with id(#) that we do in HTML but It's not working out. Can you suggest a best way to do in Angular>



Route One (/route1)



<div class="div1">
<p>hi</p>
</div>

<div class="div2">
<p>hello</p>
</div>


Route two (/route2)



<button (click)="getDiv()"></button>


TS



getDiv()

this.router.navigate(['/route1']); // I need to get div1 of route1 here










share|improve this question






















  • So you basically want to do an anchor link using routing? If yes, that's not how route works.

    – Jacopo Sciampi
    Mar 8 at 11:27











  • By this.router.navigate(['/route1']); , we can go to particular route know. So, Is there is any way to get the div of that route is what I am asking

    – Felix Christo
    Mar 8 at 11:30











  • You could send the id of the div as param and handle the scrolling on your target component

    – FabioG
    Mar 8 at 11:30











  • gotodiv(id) const element = document.getElemnetById(id); if (element) element.scrollIntoView( behavior: 'smooth', block: 'start' );

    – Joel Joseph
    Mar 8 at 11:35












  • This is typescript

    – Felix Christo
    Mar 8 at 11:36













0












0








0








I have two routes. From one route I need to get another route's div element by button click. I done a similar way with id(#) that we do in HTML but It's not working out. Can you suggest a best way to do in Angular>



Route One (/route1)



<div class="div1">
<p>hi</p>
</div>

<div class="div2">
<p>hello</p>
</div>


Route two (/route2)



<button (click)="getDiv()"></button>


TS



getDiv()

this.router.navigate(['/route1']); // I need to get div1 of route1 here










share|improve this question














I have two routes. From one route I need to get another route's div element by button click. I done a similar way with id(#) that we do in HTML but It's not working out. Can you suggest a best way to do in Angular>



Route One (/route1)



<div class="div1">
<p>hi</p>
</div>

<div class="div2">
<p>hello</p>
</div>


Route two (/route2)



<button (click)="getDiv()"></button>


TS



getDiv()

this.router.navigate(['/route1']); // I need to get div1 of route1 here







angular typescript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 11:26









Felix ChristoFelix Christo

487




487












  • So you basically want to do an anchor link using routing? If yes, that's not how route works.

    – Jacopo Sciampi
    Mar 8 at 11:27











  • By this.router.navigate(['/route1']); , we can go to particular route know. So, Is there is any way to get the div of that route is what I am asking

    – Felix Christo
    Mar 8 at 11:30











  • You could send the id of the div as param and handle the scrolling on your target component

    – FabioG
    Mar 8 at 11:30











  • gotodiv(id) const element = document.getElemnetById(id); if (element) element.scrollIntoView( behavior: 'smooth', block: 'start' );

    – Joel Joseph
    Mar 8 at 11:35












  • This is typescript

    – Felix Christo
    Mar 8 at 11:36

















  • So you basically want to do an anchor link using routing? If yes, that's not how route works.

    – Jacopo Sciampi
    Mar 8 at 11:27











  • By this.router.navigate(['/route1']); , we can go to particular route know. So, Is there is any way to get the div of that route is what I am asking

    – Felix Christo
    Mar 8 at 11:30











  • You could send the id of the div as param and handle the scrolling on your target component

    – FabioG
    Mar 8 at 11:30











  • gotodiv(id) const element = document.getElemnetById(id); if (element) element.scrollIntoView( behavior: 'smooth', block: 'start' );

    – Joel Joseph
    Mar 8 at 11:35












  • This is typescript

    – Felix Christo
    Mar 8 at 11:36
















So you basically want to do an anchor link using routing? If yes, that's not how route works.

– Jacopo Sciampi
Mar 8 at 11:27





So you basically want to do an anchor link using routing? If yes, that's not how route works.

– Jacopo Sciampi
Mar 8 at 11:27













By this.router.navigate(['/route1']); , we can go to particular route know. So, Is there is any way to get the div of that route is what I am asking

– Felix Christo
Mar 8 at 11:30





By this.router.navigate(['/route1']); , we can go to particular route know. So, Is there is any way to get the div of that route is what I am asking

– Felix Christo
Mar 8 at 11:30













You could send the id of the div as param and handle the scrolling on your target component

– FabioG
Mar 8 at 11:30





You could send the id of the div as param and handle the scrolling on your target component

– FabioG
Mar 8 at 11:30













gotodiv(id) const element = document.getElemnetById(id); if (element) element.scrollIntoView( behavior: 'smooth', block: 'start' );

– Joel Joseph
Mar 8 at 11:35






gotodiv(id) const element = document.getElemnetById(id); if (element) element.scrollIntoView( behavior: 'smooth', block: 'start' );

– Joel Joseph
Mar 8 at 11:35














This is typescript

– Felix Christo
Mar 8 at 11:36





This is typescript

– Felix Christo
Mar 8 at 11:36












2 Answers
2






active

oldest

votes


















3














If you are using angular 6.1+ version you can enable anchorScrolling manually



app.module.ts



@NgModule(
imports: [ BrowserModule, FormsModule, RouterModule.forRoot(route,
anchorScrolling: 'enabled'
) ],
declarations: [ AppComponent],
bootstrap: [ AppComponent ]
)


Then specifies the id on the div which you want to scroll to



router-a.component.ts



<div class="div1" id="div1">
<p>Div1</p>
</div>

<div class="div2" id="div2" >
<p>Div2</p>
</div>


Finall Use fragment to navigate to the current div location



getDiv() 
this.router.navigate(['/route2'], fragment: 'div2' );



Example:https://stackblitz.com/edit/angular-h7bvyu






share|improve this answer






























    -1














    your html should be in a different module and routing should be configured. Using the following code in the html would don the same routing.



    <button [routerLink]="['/route1']">View All</button>


    your router should be configured with the root.






    share|improve this answer























    • I want to go to /route1 's particular div not /route1

      – Felix Christo
      Mar 8 at 12:01











    • you have to add that div into another module and do the routing separately. You can't route to specific div in the same html via route. Just use ngif to show hide that div for the click action.

      – Osanda Wedamulla
      Mar 8 at 12:08










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062285%2fgo-to-particular-routes-div-element%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    If you are using angular 6.1+ version you can enable anchorScrolling manually



    app.module.ts



    @NgModule(
    imports: [ BrowserModule, FormsModule, RouterModule.forRoot(route,
    anchorScrolling: 'enabled'
    ) ],
    declarations: [ AppComponent],
    bootstrap: [ AppComponent ]
    )


    Then specifies the id on the div which you want to scroll to



    router-a.component.ts



    <div class="div1" id="div1">
    <p>Div1</p>
    </div>

    <div class="div2" id="div2" >
    <p>Div2</p>
    </div>


    Finall Use fragment to navigate to the current div location



    getDiv() 
    this.router.navigate(['/route2'], fragment: 'div2' );



    Example:https://stackblitz.com/edit/angular-h7bvyu






    share|improve this answer



























      3














      If you are using angular 6.1+ version you can enable anchorScrolling manually



      app.module.ts



      @NgModule(
      imports: [ BrowserModule, FormsModule, RouterModule.forRoot(route,
      anchorScrolling: 'enabled'
      ) ],
      declarations: [ AppComponent],
      bootstrap: [ AppComponent ]
      )


      Then specifies the id on the div which you want to scroll to



      router-a.component.ts



      <div class="div1" id="div1">
      <p>Div1</p>
      </div>

      <div class="div2" id="div2" >
      <p>Div2</p>
      </div>


      Finall Use fragment to navigate to the current div location



      getDiv() 
      this.router.navigate(['/route2'], fragment: 'div2' );



      Example:https://stackblitz.com/edit/angular-h7bvyu






      share|improve this answer

























        3












        3








        3







        If you are using angular 6.1+ version you can enable anchorScrolling manually



        app.module.ts



        @NgModule(
        imports: [ BrowserModule, FormsModule, RouterModule.forRoot(route,
        anchorScrolling: 'enabled'
        ) ],
        declarations: [ AppComponent],
        bootstrap: [ AppComponent ]
        )


        Then specifies the id on the div which you want to scroll to



        router-a.component.ts



        <div class="div1" id="div1">
        <p>Div1</p>
        </div>

        <div class="div2" id="div2" >
        <p>Div2</p>
        </div>


        Finall Use fragment to navigate to the current div location



        getDiv() 
        this.router.navigate(['/route2'], fragment: 'div2' );



        Example:https://stackblitz.com/edit/angular-h7bvyu






        share|improve this answer













        If you are using angular 6.1+ version you can enable anchorScrolling manually



        app.module.ts



        @NgModule(
        imports: [ BrowserModule, FormsModule, RouterModule.forRoot(route,
        anchorScrolling: 'enabled'
        ) ],
        declarations: [ AppComponent],
        bootstrap: [ AppComponent ]
        )


        Then specifies the id on the div which you want to scroll to



        router-a.component.ts



        <div class="div1" id="div1">
        <p>Div1</p>
        </div>

        <div class="div2" id="div2" >
        <p>Div2</p>
        </div>


        Finall Use fragment to navigate to the current div location



        getDiv() 
        this.router.navigate(['/route2'], fragment: 'div2' );



        Example:https://stackblitz.com/edit/angular-h7bvyu







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 12:14









        ChellappanChellappan

        5,7812421




        5,7812421























            -1














            your html should be in a different module and routing should be configured. Using the following code in the html would don the same routing.



            <button [routerLink]="['/route1']">View All</button>


            your router should be configured with the root.






            share|improve this answer























            • I want to go to /route1 's particular div not /route1

              – Felix Christo
              Mar 8 at 12:01











            • you have to add that div into another module and do the routing separately. You can't route to specific div in the same html via route. Just use ngif to show hide that div for the click action.

              – Osanda Wedamulla
              Mar 8 at 12:08















            -1














            your html should be in a different module and routing should be configured. Using the following code in the html would don the same routing.



            <button [routerLink]="['/route1']">View All</button>


            your router should be configured with the root.






            share|improve this answer























            • I want to go to /route1 's particular div not /route1

              – Felix Christo
              Mar 8 at 12:01











            • you have to add that div into another module and do the routing separately. You can't route to specific div in the same html via route. Just use ngif to show hide that div for the click action.

              – Osanda Wedamulla
              Mar 8 at 12:08













            -1












            -1








            -1







            your html should be in a different module and routing should be configured. Using the following code in the html would don the same routing.



            <button [routerLink]="['/route1']">View All</button>


            your router should be configured with the root.






            share|improve this answer













            your html should be in a different module and routing should be configured. Using the following code in the html would don the same routing.



            <button [routerLink]="['/route1']">View All</button>


            your router should be configured with the root.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 8 at 11:57









            Osanda WedamullaOsanda Wedamulla

            1256




            1256












            • I want to go to /route1 's particular div not /route1

              – Felix Christo
              Mar 8 at 12:01











            • you have to add that div into another module and do the routing separately. You can't route to specific div in the same html via route. Just use ngif to show hide that div for the click action.

              – Osanda Wedamulla
              Mar 8 at 12:08

















            • I want to go to /route1 's particular div not /route1

              – Felix Christo
              Mar 8 at 12:01











            • you have to add that div into another module and do the routing separately. You can't route to specific div in the same html via route. Just use ngif to show hide that div for the click action.

              – Osanda Wedamulla
              Mar 8 at 12:08
















            I want to go to /route1 's particular div not /route1

            – Felix Christo
            Mar 8 at 12:01





            I want to go to /route1 's particular div not /route1

            – Felix Christo
            Mar 8 at 12:01













            you have to add that div into another module and do the routing separately. You can't route to specific div in the same html via route. Just use ngif to show hide that div for the click action.

            – Osanda Wedamulla
            Mar 8 at 12:08





            you have to add that div into another module and do the routing separately. You can't route to specific div in the same html via route. Just use ngif to show hide that div for the click action.

            – Osanda Wedamulla
            Mar 8 at 12:08

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062285%2fgo-to-particular-routes-div-element%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

            Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

            How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page