我正在尝试通过 angularja 将 Vexflow sheetmusic 动态加载到 Divng-bind-html中$sce.trustAsHtml("<div id='boo'></div>")。这适用于$sce.trustAsHtml("<p>Hello World</p>"). 放入<div id='boo'></div>页面正文也可以。它不会将乐谱加载到带有 ng-bind-html 的 div 中$sce.trustAsHtml("<div id='boo'></div>")。
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9 /angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-sanitize.js"></script>
<script src="https://unpkg.com/vexflow/releases/vexflow-debug.js"> </script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-bind-html="html"></div>
</div>
<script>
var app = angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl", function($scope, $sce) {
$scope.html = $sce.trustAsHtml("<div id='boo'></div>");
});
id = "boo";
len =window.innerWidth/2;
VF = Vex.Flow;
// Create an SVG renderer and attach it to the DIV element named "boo".
var div = document.getElementById(id);
var renderer = new VF.Renderer(div, VF.Renderer.Backends.SVG);
// Size our svg:
renderer.resize(window.innerWidth/2 , 200);
// And get a drawing context:
var context = renderer.getContext();
// Create a stave at position 0, 40 of width of 'len' on the canvas.
var stave = new VF.Stave(0, 40, len);
// Add a clef and time signature.
stave.addClef("treble").addTimeSignature("4/4");
// Connect it to the rendering context and draw!
stave.setContext(context).draw();
</script>
</body>
</html>