angularjs通过ng-bind-html指令和$sce服务绑定html

代码:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>angularjs嵌入html</title>
</head>
<body ng-app="app" ng-controller="MainCtrl"> <div ng-bind-html="someText"></div> <script src="./assets/angular/angular.min.js"></script>
<script>
angular
.module('app', [], function () { })
.controller('MainCtrl', function ($scope, $sce) {
$scope.someText = $sce.trustAsHtml('<div style="color: red;">hello, world</div>');
});
</script>
</body>
</html>

运行结果:

angularjs通过ng-bind-html指令和$sce服务绑定html

上一篇:今天我得鼓吹一波 Kotlin


下一篇:Angular开发者手册重点翻译之指令(一)