如何实现在angular.js history.back() [英] How to implement history.back() in angular.js

查看:600
本文介绍了如何实现在angular.js history.back()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有指令,它是网站页眉与后退按钮,我想就点击返回previous页面。我该怎么做它的角方式?

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?

我曾尝试:

<header class="title">
<a class="back" ng-class="icons"><img src="../media/icons/right_circular.png" ng-click="history.back()" /></a>
<h1>{{title}}</h1>
<a href="/home" class="home" ng-class="icons"><img src="../media/icons/53-house.png" /></a>   
</header>

和是这种指令的js:

myApp.directive('siteHeader', function () {
    return {
        restrict: 'E',
        templateUrl: 'partials/siteHeader.html',
        scope: {
            title: '@title',
            icons: '@icons'
        }
    };
});

但没有任何反应。我环顾四周 $地点的angular.js API中,但没有发现有关的后退按钮或<$什么C $ C> history.back()。

but nothing happens. I looked in the angular.js API about $location but didn't find anything about back button or history.back().

推荐答案

您需要在您的指令,使用链接功能:

You need to use a link function in your directive:

link: function(scope, element, attrs) {
     element.on('click', function() {
         $window.history.back();
     });
 }

请参阅的jsfiddle

这篇关于如何实现在angular.js history.back()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆