Created
November 23, 2017 01:45
-
-
Save tedhagos/fa21d155aed6dfe73ad13a4cefed7f20 to your computer and use it in GitHub Desktop.
Directives
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
| <html ng-app="app"> | |
| <body ng-controller='ctrl'> | |
| {{ count }} | |
| {{ user.name }} | |
| <button ng-click="increase()">+</button> | |
| <div my-directive></div> | |
| </body> | |
| <script src="bower_components/angular/angular.js"></script> | |
| <script src="1.js"></script> | |
| </html> |
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
| angular.module('app', []).controller('ctrl', function($scope){ | |
| $scope.user = { | |
| name: "Misko Hevery" | |
| } | |
| $scope.increase = function() { | |
| $scope.count++; | |
| } | |
| $scope.count = 1; | |
| console.log($scope); | |
| }); | |
| angular.module('app').directive('myDirective', function(){ | |
| return { | |
| templateUrl: 'mydirective.html', | |
| restrict: 'AE', | |
| link: function(scope,el,attr){ | |
| el.text("Hello My Directive"); | |
| el.bind("mouseenter", function(){ | |
| scope.count++; | |
| console.log(scope); | |
| }) | |
| } | |
| } | |
| }); |
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
| <html ng-app="app"> | |
| <body ng-controller='ctrl'> | |
| {{ count }} | |
| <div my-directive></div> | |
| </body> | |
| <script src="bower_components/angular/angular.js"></script> | |
| <script src="2.js"></script> | |
| </html> |
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
| let mod = angular.module('app',[]); | |
| mod.controller('ctrl', function($scope){ | |
| //console.log($scope); | |
| }); | |
| mod.directive('myDirective', function(){ | |
| return { | |
| link: function(){ | |
| console.log(scope); | |
| }, | |
| controller: function($scope){ | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment