我想在确认消息中加入角度变量。经过多次尝试,任何解决方案对我都不起作用:
<a onclick="return confirm('Do you want to manage ' + {{item.name}} + ' with ...?')"
ng-href="/link={{item.ipAddress}}">{{item.name}}</a>
有人能帮上忙吗?(确认消息中没有{{item.name}}时工作正常)
发布于 2018-07-26 15:45:12
根据我对这个问题的理解,我正在写我自己的最佳解决方案,它可以帮助您解决问题。
var app = angular.module("app", []);
app.controller("MainController", function($scope, $window) {
$scope.item = {
"name": "Ronit Mukherjee",
"ipAddress": "192.197.85.39"
}
$scope.myFunc = function(name, ipAddress) {
if (confirm("Do you want to manage " + name + " with ...?")) {
$window.location.href = "/link=" + ipAddress;
}
}
});
a {
color: red;
text-decoration: underline;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-app="app">
<div ng-controller="MainController">
<a ng-click="myFunc(item.name,item.ipAddress)">{{item.name}}</a>
</div>
</body>
</html>
如果您仍然面临任何问题,请随时发表意见并消除疑虑。
https://stackoverflow.com/questions/51533067
复制相似问题