How to implement history.back() in angular.js

前端 未结 10 1709
南笙
南笙 2020-11-27 09:37

I have directive which is site header with back button and I want on click to go back to the previous page. How do I do it in the angular way?

I have tried:

10条回答
  •  眼角桃花
    2020-11-27 10:35

    In AngularJS2 I found a new way, maybe is just the same thing but in this new version :

    import {Router, RouteConfig, ROUTER_DIRECTIVES, Location} from 'angular2/router'; 
    
    (...)
    
    constructor(private _router: Router, private _location: Location) {}
    
    onSubmit() {
        (...)
        self._location.back();
    }
    

    After my function, I can see that my application is going to the previous page usgin location from angular2/router.

    https://angular.io/docs/ts/latest/api/common/index/Location-class.html

提交回复
热议问题