我正在尝试触发链接上的点击,但它只运行ng-click 来自MyScript.js:
$timeout(function () {
angular.element(document.querySelector('#cancelButton')).triggerHandler('click');
}, 0);
来自Index.cshtml:
<a href="#" ng-click="abortCart()" id="cancelButton"><input class="popupButton" type="button" value="Anuluj" /></a>
我知道我用
做的方式<a...><input... /></a>
错了, 但重要的是:如何点击链接和ng-click?
答案 0 :(得分:0)
我写了一个简单的程序来导航到链接。
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<div ng-app="app">
<div ng-controller="ctrl">
Redirect to <a href="#" ng-click="redirect()">Click Me!</a>
</div>
</div>
<script src="../lib/angular.js"></script>
<script>
var app = angular.module('app', []);
app.controller('ctrl', function ($scope, $log, $window) {
$scope.redirect = function () {
var url = "http://www.google.com";
$window.location.href = url;
};
});
</script>
</body>
</html>
这是你想要的吗?