0
(function() { 
    'use strict'; 

    angular 
     .module('app.widgets') 
     .directive('analiticsHere', analitics); 

    function analitics() { 
     var directive = { 
      template: '<div>hello world</div>' 
     }; 
     return directive; 
    } 
})(); 

Создать простую директиву. Ant попробуйте протестировать его.

inject(function($compile, $rootScope, $templateCache){ 
      compile = $compile; 
      scope = $rootScope.$new(); 
      template = $templateCache.get('scripts/widgets/templates/Analytics.html'); 
      console.log(template);//return nothing 
      var element = angular.element('<div analitics-here></div>'); 
      var compiledElement = compile(element)(scope); 
      console.log('compiledElement'); //return <div analitics-here="" class="ng-scope"></div> 
     }); 

Не добавляйте код шаблона, если я использую шаблон в директиве. Но ngHtml2JsPreprocessor создает html.js из любых моих html-файлов.

Как заставить его работать? Есть идеи?

ответ

0

Try следующий код

inject(function($injector){ 
     compile = $injector.get("$compile"); 
     scope = $injector.get("$rootScope").$new(); 
     template =$injector.get("$templateCache").get('scripts/widgets/templates/Analytics.html'); 
     console.log(template); 
     var element = angular.element('<div analitics-here></div>'); 
     var compiledElement = compile(element)(scope); 
     console.log('compiledElement'); class="ng-scope"></div> 
    });