Skip to content

Instantly share code, notes, and snippets.

@gmittica
Created October 10, 2017 10:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gmittica/2678e7423f16aaffd328dcd2fa25a3a6 to your computer and use it in GitHub Desktop.
Lesson // source http://jsbin.com/vazedi
<!DOCTYPE html>
<html>
<head>
<script src="https://rawgit.com/angular/bower-angular/master/angular.min.js"></script>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Lesson</title>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div class="container">
<h1>Directives</h1>
<p>Name in parent $scope:
{{ name }}
</p>
<my-directive
my-func="test(msg)"
my-name="{{ name }}"></my-directive>
</div>
<script id="jsbin-javascript">
angular.module("myApp", [])
.controller("myCtrl", ['$scope', function($scope) {
// ctrl code here
$scope.name = "Batman";
$scope.test = function(a) {
console.log(a);
};
}])
.directive("myDirective", [function() {
return {
restrict: 'AE',
replace: true,
template: '<h2 ng-click="myFunc({msg: myName})">hello {{ myName }}</h2>',
scope: {
myName: "@",
myFunc: "&"
},
link: function(scope) {
//scope.myName = "JOKER";
}
};
}]);
;
</script>
<script id="jsbin-source-javascript" type="text/javascript">angular.module("myApp", [])
.controller("myCtrl", ['$scope', function($scope) {
// ctrl code here
$scope.name = "Batman";
$scope.test = function(a) {
console.log(a);
};
}])
.directive("myDirective", [function() {
return {
restrict: 'AE',
replace: true,
template: '<h2 ng-click="myFunc({msg: myName})">hello {{ myName }}</h2>',
scope: {
myName: "@",
myFunc: "&"
},
link: function(scope) {
//scope.myName = "JOKER";
}
};
}]);
;</script></body>
</html>
angular.module("myApp", [])
.controller("myCtrl", ['$scope', function($scope) {
// ctrl code here
$scope.name = "Batman";
$scope.test = function(a) {
console.log(a);
};
}])
.directive("myDirective", [function() {
return {
restrict: 'AE',
replace: true,
template: '<h2 ng-click="myFunc({msg: myName})">hello {{ myName }}</h2>',
scope: {
myName: "@",
myFunc: "&"
},
link: function(scope) {
//scope.myName = "JOKER";
}
};
}]);
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment