Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 78656fe

Browse files
committed
feat($compile) add locals, isolate scope, transclusion
1 parent cb10ccc commit 78656fe

13 files changed

+838
-107
lines changed

src/AngularPublic.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ function publishExternalAPI(angular){
9494
ngStyle: ngStyleDirective,
9595
ngSwitch: ngSwitchDirective,
9696
ngOptions: ngOptionsDirective,
97-
ngView: ngViewDirective
97+
ngView: ngViewDirective,
98+
ngTransclude: ngTranscludeDirective
9899
}).
99100
directive(ngEventDirectives).
100101
directive(ngAttributeAliasDirectives);

src/angular-bootstrap.js

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
globalVars = {};
102102

103103
bindJQuery();
104+
publishExternalAPI(window.angular);
104105

105106
angularInit(document, angular.bootstrap);
106107
}

src/angular-mocks.js

+3
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,9 @@ window.jstestdriver && (function(window) {
14581458
args.push(angular.mock.dump(arg));
14591459
});
14601460
jstestdriver.console.log.apply(jstestdriver.console, args);
1461+
if (window.console) {
1462+
window.console.log.apply(window.console, args);
1463+
}
14611464
};
14621465
})(window);
14631466

src/directives.js

+58-11
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,7 @@ var ngInitDirective = valueFn({
133133
var ngControllerDirective = ['$controller', '$window', function($controller, $window) {
134134
return {
135135
scope: true,
136-
compile: function() {
137-
return {
138-
pre: function(scope, element, attr) {
139-
var expression = attr.ngController,
140-
Controller = getter(scope, expression, true) || getter($window, expression, true);
141-
142-
assertArgFn(Controller, expression);
143-
$controller(Controller, scope);
144-
}
145-
};
146-
}
136+
controller: '@'
147137
}
148138
}];
149139

@@ -264,6 +254,7 @@ var ngBindHtmlDirective = ['$sanitize', function($sanitize) {
264254
var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
265255
return function(scope, element, attr) {
266256
var interpolateFn = $interpolate(attr.ngBindTemplate);
257+
var interpolateFn = $interpolate(element.attr(attr.$attr.ngBindTemplate));
267258
element.addClass('ng-binding').data('$binding', interpolateFn);
268259
scope.$watch(interpolateFn, function(value) {
269260
element.text(value);
@@ -921,3 +912,59 @@ function ngAttributeAliasDirective(propName, attrName) {
921912
var ngAttributeAliasDirectives = {};
922913
forEach(BOOLEAN_ATTR, ngAttributeAliasDirective);
923914
ngAttributeAliasDirective(null, 'src');
915+
916+
/**
917+
* @ngdoc directive
918+
* @name angular.module.ng.$compileProvider.directive.ng:transclude
919+
*
920+
* @description
921+
* Insert the transcluded DOM here.
922+
*
923+
* @element ANY
924+
*
925+
* @example
926+
<doc:example module="transclude">
927+
<doc:source>
928+
<script>
929+
function Ctrl($scope) {
930+
$scope.title = 'Lorem Ipsum';
931+
$scope.text = 'Neque porro quisquam est qui dolorem ipsum quia dolor...';
932+
}
933+
934+
angular.module('transclude', [])
935+
.directive('pane', function(){
936+
return {
937+
transclude: true,
938+
scope: 'isolate',
939+
locals: { title:'bind' },
940+
template: '<div style="border: 1px solid black;">' +
941+
'<div style="background-color: gray">{{title}}</div>' +
942+
'<div ng-transclude></div>' +
943+
'</div>'
944+
};
945+
});
946+
</script>
947+
<div ng:controller="Ctrl">
948+
<input ng:model="title"><br>
949+
<textarea ng:model="text"></textarea> <br/>
950+
<pane title="{{title}}">{{text}}</pane>
951+
</div>
952+
</doc:source>
953+
<doc:scenario>
954+
it('should have transcluded', function() {
955+
input('title').enter('TITLE');
956+
input('text').enter('TEXT');
957+
expect(binding('title')).toEqual('TITLE');
958+
expect(binding('text')).toEqual('TEXT');
959+
});
960+
</doc:scenario>
961+
</doc:example>
962+
*
963+
*/
964+
var ngTranscludeDirective = valueFn({
965+
controller: ['$transclude', '$element', function($transclude, $element) {
966+
$transclude(function(clone) {
967+
$element.append(clone);
968+
});
969+
}]
970+
});

0 commit comments

Comments
 (0)