如何使用angularjs中的按钮单击事件将一个html页面重定向到另一个页面 [英] how to redirect one html page to another using button click event in angularjs
本文介绍了如何使用angularjs中的按钮单击事件将一个html页面重定向到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 angularjs 指令重定向另一个 html 页面.我正在指令内编写点击函数,但我在警告框中获取页面名称而不是重定向到另一个 html 页面.
i am using angularjs directive to redirect another html page.i am writing click function inside directive but i am getting page name in alert box not redirect to another html page.
sample.html:
sample.html:
<test1>
<button data-ng-click="click('/page.html')">Click</button>
</test1>
sample.js:
app.directive('test1',['$location', function(location) {
function compile(scope, element, attributes,$location) {
return{
post:function(scope, element, iAttrs,$location) {
scope.click=function(path)
{
alert("click"+path);
$location.path('/path');
};
}
};
}
return({
compile: compile,
restrict: 'AE',
});
}]);
我想重定向 page.html 如何做到这一点,请建议我.谢谢.
i want to redirect page.html how to do this please suggest me. Thanks.
推荐答案
在 html,
<button ng-click="redirect()">Click</button>
在JS中,
$scope.redirect = function(){
window.location = "#/page.html";
}
希望能帮到你......
Hope it helps.....
这篇关于如何使用angularjs中的按钮单击事件将一个html页面重定向到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文