here's a plnkr http://plnkr.co/edit/Q5oD65wSvBAemf5BCDL7?p=preview
In this case you can use $compile (you still need a $scope from the example, but $compile pretty much answers your question I guess),
var $compile = chartsInjector.get("$compile");
console.log("$compile=",$compile);
var chartsDirective = $compile("<div charts></div>");
console.log(chartsDirective);
...
var blockapp = angular.module('blockApp', []);
blockapp.run(function(){
// create a new injector
var chartsInjector = angular.injector(['ng', 'angularCharts']);
console.log("chartsInjector=",chartsInjector);
var $compile = chartsInjector.get("$compile");
console.log("$compile=",$compile);
var chartsDirective = $compile("<div charts></div>");
console.log(chartsDirective);
})
note that you will be creating multiple injectors here.
injector 1) created by ng-app
<body ng-app="blockApp">
injector 2) created by angular.injector()
var chartsInjector = angular.injector(['ng', 'angularCharts']);
whole code
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script type="text/javascript">
// creating the angularcharts
angular.module('angularCharts', []).directive('charts', function(){
return function(){}
});
// creating blockapp
angular.module('blockApp', []).directive('', []);
// retrieving the created blockapp
// NOTE! ng-app will create a new injector for blockapp
var blockapp = angular.module('blockApp', []);
blockapp.run(function(){
// create a new injector
var chartsInjector = angular.injector(['ng', 'angularCharts']);
console.log("chartsInjector=",chartsInjector);
var $compile = chartsInjector.get("$compile");
console.log("$compile=",$compile);
var chartsDirective = $compile("<div charts></div>");
console.log(chartsDirective);
})
</script>
</head>
<body ng-app="blockApp">
</body>
</html>
plnkr http://plnkr.co/edit/Q5oD65wSvBAemf5BCDL7?p=preview
getit.angular.injector(['ng', 'other_module']).get('directiveNameDirective');postFix directive name with "Directive"Error: [$injector:unpr] Unknown provider: $rootElementProvider <- $rootElement <- acChartDirective. In my case your suggestion isangular.injector(['ng', 'angularCharts']).get('acChartDirective');angular.injector(['ng','other_module']).get('directiveNameDirectirve)calls toother_module.directive('directiveName, function() {})but angular still doesn't understanddirectiveName. I think we still need registerdirectiveNameto angular...