There is situations where you might want to add additional methods to angular.module . This was easy to accomplish, and can be a handy technique.
//for Directive Template<Hello></Hello>//for Directive Controller<binMenu-item ng-repeat= "category in categories"class= "Menu-animation"Ng-class= "{' Highlight ': Mouse_over}"Ng-mouseenter= "Mouse_over = True"Ng-mouseleave= "Mouse_over = False"Ng-class= "{' Active ': iscurrentcategory (category)}"> <aNg-click= "setcurrentcategory (category)">{{Category.name}}</a> </Li>
varOriginal =Angular.module;angular.module=function(name, deps, config) {varmodule =original (name, Deps, config); Module.quicktemplate=function(name, template) {module.directive (name,function() { return{template:template}}); }; Module.quickcontroller=function(name, Controller) {module.directive (name,function() { return{Controller:controller}}) }; returnmodule;};
Use:we comment out the meunitem directive, instead using Quickcontroller method added to the end of the file.
Angular.module (' categories ', [ ' Eggly.models.categories ', ' Nganimate ']). config (function($stateProvider) {$stateProvider. State (' Eggly.categories ', {URL:‘/‘, Views: {' [Email protected] ': {controller:' Categoriescontroller ', Templateurl:' App/categories/categories.tmpl.html ' }, ' [Email protected] ': {controller:' Bookmarkscontroller ', Templateurl:' App/categories/bookmarks/bookmarks.tmpl.html ' } } }); }). controller (' Categoriescontroller ',function($scope) {})/*. directive (' MenuItem ', function () {var controller = function ($scope) {$scope. Mouse_over = false; }; return {Controller:controller}})*/. Animation ('. Menu-animation ',function () { return{beforeaddclass:function(element, className, done) {if(ClassName = = ' Highlight ') {tweenlite.to (element,0.2, {width:' 223 ', Borderleft:' 10px solid #89CD25 ', oncomplete:done}); Tweenlite.to (Element.find (' A '), 0.2, {color:"#89CD25" }); } Else{done (); }}, Beforeremoveclass:function(element, className, done) {if(ClassName = = ' Highlight ') {tweenlite.to (element,0.4, {width:' 180 ', Borderleft:' 5px solid #333 ', oncomplete:done}); Tweenlite.to (Element.find (' A '), 0.4, {color:"#5bc0de" }); } Else{done (); } } }; }). Quickcontroller (' MenuItem ',function($scope) {$scope. Mouse_over=false; });
There are to add quickcontroller to the end of the file, otherwise, it breaks the chain.
[AngularJS] Adding Custom Methods to Angular.module