V
V
vasIvas2015-06-26 21:44:32
Angular
vasIvas, 2015-06-26 21:44:32

How to run snippet directives for angulsrjs?

Sublime text 3 has a directive snippet that I can't seem to get to run.
Below is the snippet itself, if someone has come across a similar one, fill it in correctly -

<div my-directive="good"></div>
.directive('', ['', function(){
  // Runs during compile
  return {
    // name: '',
    // priority: 1,
    // terminal: true,
    // scope: {}, // {} = isolate, true = child, false/undefined = no change
    // controller: function($scope, $element, $attrs, $transclude) {},
    // require: 'ngModel', // Array = multiple requires, ? = optional, ^ = check parent elements
    // restrict: 'A', // E = Element, A = Attribute, C = Class, M = Comment
    // template: '',
    // templateUrl: '',
    // replace: true,
    // transclude: true,
    // compile: function(tElement, tAttrs, function transclude(function(scope, cloneLinkingFn){ return function linking(scope, elm, attrs){}})),
    link: function($scope, iElm, iAttrs, controller) {
      
    }
  };
}]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-06-26
@vasIvas

https://docs.angularjs.org/guide/directive
If we fill it out for you, you'd be kind enough to decorate:
Updated
Damn... didn't think you'd do that well... now I can't get away...
what's going on here. The first empty quotes are the name of the directive. Written in camel case, used with underscore (as it happened with DOM).

.directive('someDirective', fn);
// <some-directive></some-directive>

further, we have an array in which there are only empty quotes and a function. This is such a castle (it won’t work out differently) to describe the dependencies of the directive. You can replace the array simply with a function, but if you write dependencies on services (for example, on $q), everything will break during minification. The fact is that if we did not explicitly specify the $inject property for the function we are passing, then angular will try to pick up dependencies by the names of the arguments. And then there are problems - during minification, the names of the arguments change and ... everything is bad. Therefore, we either explicitly write $inject or use array notation, in which the original service names go first, and the last element of the array is the function into which it will all be injected. Well, in fairness - there is ng-annotate which automates all this.
As for properties, the basics - a link is a function that links a particular DOM element and a directive. In fact, this is where work with the DOM should take place. Another of the frequently used properties is controller , there actually .... a controller that contains exactly the logic of the directive. The controller can rummage between dependent directives (dependencies are described through require and describe the position relative to other directives in the DOM).
But compile is perhaps the most rarely used property, since these are very specific tasks needed to use the full power of this thing (usually something related to optimizations).
Actually, much has been written in directives on how and what to write.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question