diff options
| author | Misko Hevery | 2012-01-27 16:18:16 -0800 |
|---|---|---|
| committer | Misko Hevery | 2012-02-21 22:46:00 -0800 |
| commit | 78656fe0dfc99c341ce02d71e7006e9c05b1fe3f (patch) | |
| tree | a68731c4c1675047da65b23ccf3d562324324081 /src/directives.js | |
| parent | cb10ccc44fa78b82c80afa1cb5dac2c34fdf24b7 (diff) | |
| download | angular.js-78656fe0dfc99c341ce02d71e7006e9c05b1fe3f.tar.bz2 | |
feat($compile) add locals, isolate scope, transclusion
Diffstat (limited to 'src/directives.js')
| -rw-r--r-- | src/directives.js | 69 |
1 files changed, 58 insertions, 11 deletions
diff --git a/src/directives.js b/src/directives.js index c6cc0b15..39308b1a 100644 --- a/src/directives.js +++ b/src/directives.js @@ -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: '@' } }]; @@ -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); @@ -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); + }); + }] +}); |
