href overrides ng-click in Angular.js

2019-01-03 02:15发布

When both, href and ng-click attributes are defined:

<a href="#" ng-click="logout()">Sign out</a>

the href attribute takes precedence over ng-click.

I am looking for a way to raise priority of ng-click.

href is required for Twitter Bootstrap, I can't remove it.

15条回答
家丑人穷心不美
2楼-- · 2019-01-03 03:17

You should probably just use a button tag if you don't need a uri.

查看更多
forever°为你锁心
3楼-- · 2019-01-03 03:17

This worked for me in IE 9 and AngularJS v1.0.7:

<a href="javascript:void(0)" ng-click="logout()">Logout</a>

Thanks to duckeggs' comment for the working solution!

查看更多
叼着烟拽天下
4楼-- · 2019-01-03 03:18

I'll add for you an example that work for me and you can change it as you want.

I add the bellow code inside my controller.

     $scope.showNumberFct = function(){
        alert("Work!!!!");
     }

and for my view page I add the bellow code.

<a  href="" ng-model="showNumber" ng-click="showNumberFct()" ng-init="showNumber = false" >Click Me!!!</a>
查看更多
登录 后发表回答