Where does Angular store directory information?

Where does Angular store directive templates?

I have a module / directive, and I want to get the template that it uses in another directive. In particular, I want to view raw HTML and variable names with scope

Some directives

var someModule = angular.module ('someModule', []);

someModule.controller ('someModuleCtrl', ['$ scope',
    function ($ scope) {
        'use strict';
        // Do stuff
        };
    }]);

someModule.directive ('someModule', [
    function () {
        'use strict';
        return {
            restrict: 'AE',
            template: 'some HTML and {{AngularVar}}',
            scope: {
                input1: '=',
                input2: '=',
                optional1: '=?'
            },
            controller: "someModuleCtrl"
        };
    }]);

Some other directive in which I want to see the raw HTML of another tempalte directive

var myModule = angular.module ('MyModule', []);
myModule.controller ('MyModuleCtrl', ['$ scope', 
    function ($ scope) {
        console.log (-------- someModule.directives ['someModule']. template ---------);
    }]);
+4
source share
1 answer

Directives are introduced as nameDirective, here is an example:

.directive("one", function () {
  return {
    template: "<div>{{something}}</div>",
    scope: {
      a: "@",
      b: "=",
      c: "&test"
    }
  };
})
.directive("two", function (oneDirective) {
  return function link () {
    var d = oneDirective[0];
    console.log(d.scope, d.template)
  };
});

/*
[object Object] {
  a: "@",
  b: "=",
  c: "&test"
}
"<div>{{something}}</div>"
*/

JSBin .

0
source

All Articles