Last active
October 16, 2016 08:01
-
-
Save nopium/0af54d1dd2ea6096ad1e1352ecbb0b96 to your computer and use it in GitHub Desktop.
Angular Tips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Directives | |
| ========== | |
| Directive calls controller | |
| ------------------------- | |
| app.controller("AppCtrl", function($scope) { | |
| $scope.func = function() { | |
| alert("Controller's function published on scope"); | |
| } | |
| } | |
| app.directive(“enter”, function(scope, el, attr) { | |
| element.bind(“mouseenter”, function() { | |
| scope.$apply(attr.enter); | |
| } | |
| } | |
| <div ng-controller="AppCtrl"> | |
| <div enter="func()">Put your mouse here to call controller's func from directive</div> | |
| </div> | |
| Directive calls directive | |
| ------------------------- | |
| app.directive("parentDirective", function(){ | |
| return { | |
| scope: {}, //! isolates scope | |
| controller: function($scope) { | |
| $this.func1 = function(){}... | |
| }, | |
| link: function(scope, element) { | |
| element.addClass(...) | |
| element.bind("event", function(){...}) | |
| } | |
| } | |
| }); | |
| app.directive("childdirective", function() { | |
| return { | |
| require:"parentdirective", | |
| link: function(scope, element, attrs, parentCtrl){ | |
| parentCtrl.func1(...) | |
| } | |
| } | |
| } | |
| ht |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment