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

Commit

Permalink
feat($compile) add locals, isolate scope, transclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Feb 22, 2012
1 parent cb10ccc commit 78656fe
Show file tree
Hide file tree
Showing 13 changed files with 838 additions and 107 deletions.
3 changes: 2 additions & 1 deletion src/AngularPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ function publishExternalAPI(angular){
ngStyle: ngStyleDirective,
ngSwitch: ngSwitchDirective,
ngOptions: ngOptionsDirective,
ngView: ngViewDirective
ngView: ngViewDirective,
ngTransclude: ngTranscludeDirective
}).
directive(ngEventDirectives).
directive(ngAttributeAliasDirectives);
Expand Down
1 change: 1 addition & 0 deletions src/angular-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
globalVars = {};

bindJQuery();
publishExternalAPI(window.angular);

angularInit(document, angular.bootstrap);
}
Expand Down
3 changes: 3 additions & 0 deletions src/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,9 @@ window.jstestdriver && (function(window) {
args.push(angular.mock.dump(arg));
});
jstestdriver.console.log.apply(jstestdriver.console, args);
if (window.console) {
window.console.log.apply(window.console, args);
}
};
})(window);

Expand Down
69 changes: 58 additions & 11 deletions src/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,7 @@ var ngInitDirective = valueFn({
var ngControllerDirective = ['$controller', '$window', function($controller, $window) {
return {
scope: true,
compile: function() {
return {
pre: function(scope, element, attr) {
var expression = attr.ngController,
Controller = getter(scope, expression, true) || getter($window, expression, true);

assertArgFn(Controller, expression);
$controller(Controller, scope);
}
};
}
controller: '@'
}
}];

Expand Down Expand Up @@ -264,6 +254,7 @@ var ngBindHtmlDirective = ['$sanitize', function($sanitize) {
var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
return function(scope, element, attr) {
var interpolateFn = $interpolate(attr.ngBindTemplate);
var interpolateFn = $interpolate(element.attr(attr.$attr.ngBindTemplate));
element.addClass('ng-binding').data('$binding', interpolateFn);
scope.$watch(interpolateFn, function(value) {
element.text(value);
Expand Down Expand Up @@ -921,3 +912,59 @@ function ngAttributeAliasDirective(propName, attrName) {
var ngAttributeAliasDirectives = {};
forEach(BOOLEAN_ATTR, ngAttributeAliasDirective);
ngAttributeAliasDirective(null, 'src');

/**
* @ngdoc directive
* @name angular.module.ng.$compileProvider.directive.ng:transclude
*
* @description
* Insert the transcluded DOM here.
*
* @element ANY
*
* @example
<doc:example module="transclude">
<doc:source>
<script>
function Ctrl($scope) {
$scope.title = 'Lorem Ipsum';
$scope.text = 'Neque porro quisquam est qui dolorem ipsum quia dolor...';
}
angular.module('transclude', [])
.directive('pane', function(){
return {
transclude: true,
scope: 'isolate',
locals: { title:'bind' },
template: '<div style="border: 1px solid black;">' +
'<div style="background-color: gray">{{title}}</div>' +
'<div ng-transclude></div>' +
'</div>'
};
});
</script>
<div ng:controller="Ctrl">
<input ng:model="title"><br>
<textarea ng:model="text"></textarea> <br/>
<pane title="{{title}}">{{text}}</pane>
</div>
</doc:source>
<doc:scenario>
it('should have transcluded', function() {
input('title').enter('TITLE');
input('text').enter('TEXT');
expect(binding('title')).toEqual('TITLE');
expect(binding('text')).toEqual('TEXT');
});
</doc:scenario>
</doc:example>
*
*/
var ngTranscludeDirective = valueFn({
controller: ['$transclude', '$element', function($transclude, $element) {
$transclude(function(clone) {
$element.append(clone);
});
}]
});
Loading

0 comments on commit 78656fe

Please sign in to comment.