Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
angularjs,这是一个 scope 中带有 html 代码的处理方式。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div test ng-bind-html="title"></div>
<script>
app.directive('test', function ($sce) {
return {
restrict: 'A',
link: function (scope) {
scope.title = '<h1>大标题</h1>';
scope.toTrusted = function(html) {
return $sce.trustAsHtml(html);
};
}
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment