Skip to content

Instantly share code, notes, and snippets.

@tedhagos
Created November 23, 2017 01:45
Show Gist options
  • Select an option

  • Save tedhagos/fa21d155aed6dfe73ad13a4cefed7f20 to your computer and use it in GitHub Desktop.

Select an option

Save tedhagos/fa21d155aed6dfe73ad13a4cefed7f20 to your computer and use it in GitHub Desktop.
Directives
<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>
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);
})
}
}
});
<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>
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