Vì vậy, về cơ bản tôi muốn có thể kích hoạt một sự kiện và sau đó có một biên dịch chỉ thị và chèn tự của nó vào một vị trí trong DOM. Hiện nay tôi có một cái gì đó như thế nàyChèn chỉ thị theo chương trình góc
//controller
angular.module('app').controller('MainCtrl', function ($scope, $compile) {
$scope.$on('insertItem',function(ev,attrs){
var el = $compile("<chart></chart>")($scope);
$scope.insertHere = el;
});
});
// directive
angular.module('app')
.directive('chart', function() {
return {
template: '<div>My chart</div>',
restrict: 'E',
link: function postLink(scope, element, attrs) {
element.text('this is a chart');
}
};
});
tôi có thể thấy đối tượng "el" với tất cả những gì tôi cần, nhưng tôi không thể để chèn nó vào DOM ... bất kỳ manh mối?
có thể trùng lặp của [Tự động thêm chỉ thị trong AngularJS] (http://stackoverflow.com/questions/15279244/dynamically-add -directive-in-angularjs) –