diff options
| author | Misko Hevery | 2011-10-17 16:56:56 -0700 |
|---|---|---|
| committer | Misko Hevery | 2011-11-14 16:39:31 -0800 |
| commit | 48697a2b86dbb12ea8de64cc5fece7caf68b321e (patch) | |
| tree | 1fa50659f0bb5de2640dea2a2e5bb5628f2bb14a /src/Compiler.js | |
| parent | 93b777c916ccff243c5a6080bf5f39860ac7bf39 (diff) | |
| download | angular.js-48697a2b86dbb12ea8de64cc5fece7caf68b321e.tar.bz2 | |
refactor(injector): turn scope into a service
- turn scope into a $rootScope service.
- injector is now a starting point for creating angular application.
- added inject() method which wraps jasmine its/beforeEach/afterEach,
and which allows configuration and injection of services.
- refactor tests to use inject() where possible
BREAK:
- removed angular.scope() method
Diffstat (limited to 'src/Compiler.js')
| -rw-r--r-- | src/Compiler.js | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/Compiler.js b/src/Compiler.js index 0411c70d..ee768a9d 100644 --- a/src/Compiler.js +++ b/src/Compiler.js @@ -102,11 +102,10 @@ Template.prototype = { * * * @param {string|DOMElement} element Element or HTML to compile into a template function. - * @returns {function([scope][, cloneAttachFn])} a template function which is used to bind template + * @returns {function(scope[, cloneAttachFn])} a template function which is used to bind template * (a DOM element/tree) to a scope. Where: * - * * `scope` - A {@link angular.scope Scope} to bind to. If none specified, then a new - * root scope is created. + * * `scope` - A {@link angular.scope Scope} to bind to. * * `cloneAttachFn` - If `cloneAttachFn` is provided, then the link function will clone the * `template` and call the `cloneAttachFn` function allowing the caller to attach the * cloned elements to the DOM document at the appropriate place. The `cloneAttachFn` is @@ -115,9 +114,8 @@ Template.prototype = { * * `clonedElement` - is a clone of the original `element` passed into the compiler. * * `scope` - is the current scope with which the linking function is working with. * - * Calling the template function returns the scope to which the element is bound to. It is either - * the same scope as the one passed into the template function, or if none were provided it's the - * newly create scope. + * Calling the template function returns the element of the template. It is either the original element + * passed in, or the clone of the element if the `cloneAttachFn` is provided. * * It is important to understand that the returned scope is "linked" to the view DOM, but no linking * (instance) functions registered by {@link angular.directive directives} or @@ -133,8 +131,8 @@ Template.prototype = { * - If you are not asking the linking function to clone the template, create the DOM element(s) * before you send them to the compiler and keep this reference around. * <pre> - * var view = angular.element('<p>{{total}}</p>'), - * scope = angular.compile(view)(); + * var scope = angular.injector()('$rootScope'); + * var element = angular.compile('<p>{{total}}</p>')(scope); * </pre> * * - if on the other hand, you need the element to be cloned, the view reference from the original @@ -208,17 +206,17 @@ Compiler.prototype = { } template = this.templatize(templateElement, index) || new Template(); return function(scope, cloneConnectFn){ + assertArg(scope, 'scope'); // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart // and sometimes changes the structure of the DOM. var element = cloneConnectFn ? JQLitePrototype.clone.call(templateElement) // IMPORTANT!!! : templateElement; - scope = scope || createScope(); element.data($$scope, scope); scope.$element = element; (cloneConnectFn||noop)(element, scope); template.link(element, scope); - return scope; + return element; }; }, |
