I have understood two different things:
1: The <a>
depends on the variable confirm
.
2: The action depends on the result of confirm
.
1:
First declare confirm using $scope
.
Then it determines the appearance of the <a>
using the property ng-if
.
This way you can see that if confirming is false it is not shown, and if it is true if.
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.confirmar = true;
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="[email protected]" src="https://code.angularjs.org/1.2.22/angular.js" data-semver="1.2.22"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<a href="index" ng-if='confirmar' onclick="return confirm('Are you sure?')">Index</a>
</body>
</html>
2:
Treat the true or false by a function and execute the desired result. I have not put the redirects because I do not know what you want to put exactly.
function confirmar(){
var r = confirm("¿seguro que desea volver?");
if (r == true) {
alert("\'codgio de vuelta (true)\'");
} else {
alert("\'codgio de redireccion (false)\'");
}
}
<a href="#" onclick="return confirmar();">Index</a>