我正在尝试使用angular替换div中的某些值。问题是div内容是由外部服务生成的,所以我不能只添加>>> df
lat lat_med
0 50.637578 50.637574
1 50.637574 50.637574
2 50.637574 50.637574
3 50.637408 50.637408
4 50.637578 50.637578
5 50.637408 50.637578
6 50.637578 NaN
7 50.637578 NaN
并完成它。我已经尝试了以下和一些不同的变化而没有运气
ng-model
答案 0 :(得分:2)
只需从此行中删除angular.element()
,它就可以根据您的需要运行:angular.element(document.querySelector('#maintwo')).innerHTML = r;
执行此操作,例如:document.querySelector('#maintwo').innerHTML = r;
答案 1 :(得分:1)
如果你从第3行中删除了angular.element()容器。
<!DOCTYPE html>
<html ng-app="myApp" ng-controller="myCtrl">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-sanitize.js"></script>
</head>
<body>
<button ng-click="replaceText()">
replace
</button>
<div id="maintwo">MAIN TWO</div>
<script>
var myApp = angular.module('myApp', ['ngSanitize'])
function myCtrl($scope) {
$scope.replaceText = function() {
var o = angular.element(document.querySelector('#maintwo'));
var r = o[0].innerHTML.replace('TWO','REPLACE');
document.querySelector('#maintwo').innerHTML = r;
}
}
</script>
</body>
</html>