Ich habe ein Problem, ich möchte HTML-Elemente in einer Direktive in angularjs anhängen, und ich möchte sie zum Beispiel kompilieren Ich möchte ein {{text}} anhängen und ich möchte dies kompilieren with ~~~ $ scope.text = "Beispiel ...";AngularJS Append und kompilieren in Direktive
Wie kann ich das tun? ist das möglich? Wie?
(function() {
'use strict';
var matrixelement = document.getElementById("matrixcontent");
var app = angular.module('testviewer', ['ngMaterial', 'ngSanitize']).controller('matrixviewCtrl', matrixviewCtrl);
app.directive("matrixview",function($compile){
return {
link: function (scope, iElement, iAttrs) {
var svg = angular.element("<p>{{ text }}</p>");
iElement.append($compile(svg)($scope));
}
}
});
function matrixviewCtrl($scope, $compile) {
}
})();
Sie tun es hier 'iElement.append ($ compile (svg) ($ Scope));', Was ist das Problem? –
Entfernen Sie das Dollarzeichen von der Scope-Variable in der Direktive, so dass es 'iElement.append ($ compile (svg) (scope));' – Ankh