AngularJS binds unsafe:javascript:void(0) when value is javascipt:void(0)
<a ng-attr-href="{{page==1 && 'javascript:void(0)' || '#a/'+tid+'/'+(page-1)}}">Prev</a>
I want to get that when page = 1
<a href="javascript:void(0)">Prev</a>
But the result:
<a href="unsafe:javascript:void(0)">Prev</a>
Use ng-click
in <a>
<a href="" ng-click="go(tid)">
And in controller
app.controller('whatever', function($scope, $location){
$scope.go = function(id){
if($scope.page == 1) {
return;
}
var url = '/a/' + id + '/' + ($scope.page - 1);
$location.url(url);
}
});
This way you also move logic out of template.
use ng-click on a and pass $event to your function.
<a href="#" ng-click="yourFunction($event);">Click</a>
In your function do the following
$scope.yourFunction = function(e) {
e.preventDefault();
};
链接地址: http://www.djcxy.com/p/81738.html
上一篇: 如何增加TextView Android中的文本和下划线之间的空间?
下一篇: AngularJS绑定不安全:当值为javascipt时,javascript:void(0):void(0)