加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何使用angularjs中的按钮单击事件将一个html页面重定向到另一

发布时间:2020-12-17 18:02:36 所属栏目:安全 来源:网络整理
导读:我正在使用 angularjs指令重定向另一个html page.i我在指令中编写click函数,但我在警告框中获取页面名称而不是重定向到另一个html页面. sample.html: test1button data-ng-click="click('/page.html')"Click/button/test1 sample.js: app.directive('test1
我正在使用 angularjs指令重定向另一个html page.i我在指令中编写click函数,但我在警告框中获取页面名称而不是重定向到另一个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,iAttrs,$location) {
                 scope.click=function(path)
                 { 
                     alert("click"+path);
                     $location.path('/path');
                 };
             }
         };
        }

        return({
            compile: compile,restrict: 'AE',});

    }]);

我想重定向page.html如何做到这一点请建议我.
谢谢.

解决方法

在HTML中,

<button ng-click="redirect()">Click</button>

在JS中,

$scope.redirect = function(){
  window.location = "#/page.html";
}

希望能帮助到你…..

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读