如何使用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.....