小编use*_*122的帖子

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

我正在使用angularjs指令重定向另一个html page.i我在指令中编写click函数,但我在警告框中获取页面名称而不是重定向到另一个html页面.

sample.html:

<test1>
<button data-ng-click="click('/page.html')">Click</button>
</test1>
Run Code Online (Sandbox Code Playgroud)

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',
        });

    }]);
Run Code Online (Sandbox Code Playgroud)

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

angularjs angularjs-directive

5
推荐指数
2
解决办法
7万
查看次数

标签 统计

angularjs ×1

angularjs-directive ×1