Skip to content

Commit f7303ca

Browse files
committed
added branch 'zippy_directive'. (transclusion, ng-show, templates)
1 parent 6d8dc8b commit f7303ca

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

egghead/index.html

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,29 @@
33
<head>
44
<meta charset="utf-8">
55
<title>Angular</title>
6-
<style type="text/css">
7-
.button { border: solid 1px blue; }
8-
</style>
6+
7+
<link rel="stylesheet" href="css/style.css">
8+
99
</head>
1010
<body>
11+
<h1>Angular</h1>
1112

1213
<div ng-app="app">
13-
<div ng-controller="MyCtrl">
14-
</div>
14+
15+
<input type="text" ng-model="model.prop1"> <br/>
16+
<input type="text" ng-model="model.prop2"> <br/>
17+
<input type="text" ng-model="model.prop3">
18+
19+
<zippy attrfoo="{{model.prop1}}" attrbar="{{model.prop2}}"> <!-- grabs data from chrisProp -->
20+
<!-- NOTE: content that is transcluded has access to parent scope.
21+
This is how model.content is available to the view
22+
-->
23+
<p>Third input is : "{{model.prop3}}". First input is "{{model.prop1}}".</p>
24+
</zippy>
25+
1526
</div>
1627

28+
1729
<script src="js/angular.js"></script>
1830
<script src="js/app.js"></script>
1931

egghead/js/app.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
// Define an App
22
var app = angular.module('app', []);
33

4-
// Declaring dependencies before function() protects against minification variable collision.
5-
// Dependencies are injected in the same order they are declared.
6-
app.controller('MyCtrl', ['$scope', '$http', function(a, b) {
7-
console.log(b);
8-
}]);
9-
10-
app.directive('myDirective', function($http, $parse) {
4+
app.directive('zippy', function() {
115
return {
12-
link: function(scope, elem, attrs) {
13-
console.log(scope)
6+
restrict: 'E',
7+
transclude: true,
8+
scope: {
9+
attrfoo: '@',
10+
attrbar: '@'
11+
},
12+
template: '<div>' +
13+
'<h3 ng-click="toggleContent()"> First input is: {{attrfoo}} </h3><br/>' +
14+
'Second input is: {{attrbar}} <br/>' +
15+
'<div ng-click="myFunc()" ng-show="isContentVisible" ng-transclude> </div>' +
16+
'</div>',
17+
18+
link: function(scope) {
19+
scope.isContentVisible = false;
20+
21+
scope.toggleContent = function() {
22+
scope.isContentVisible = !scope.isContentVisible;
23+
console.log('toggleContent Fired');
24+
};
25+
26+
scope.myFunc = function() {
27+
console.log('myfunct Fired')
28+
};
1429
}
1530
};
1631
});
17-
18-

0 commit comments

Comments
 (0)